realfreko commited on
Commit
e740ba1
1 Parent(s): 1ee88bc

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -4
app.py CHANGED
@@ -1,7 +1,31 @@
1
  import gradio as gr
 
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
5
 
6
- iface = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ import numpy
3
+ import tensorflow as tf
4
 
 
 
5
 
6
+
7
+ interpreter = tf.lite.Interpreter(model_path=r"C:\Users\lenwe\converted_dog_model.tflite")
8
+ interpreter.allocate_tensors()
9
+ input_details = interpreter.get_input_details()
10
+ output_details = interpreter.get_output_details()
11
+
12
+
13
+ def predict(img):
14
+
15
+ img = img/255.
16
+
17
+ interpreter.set_tensor(input_details[0]['index'], np.expand_dims(img, axis = 0).astype(np.float32))
18
+ interpreter.invoke()
19
+ pred = interpreter.get_tensor(output_details[0]['index'])
20
+
21
+ if len(pred[0]) > 1:
22
+ pred_class = class_names[tf.argmax(pred[0])]
23
+ else:
24
+ pred_class = class_names[int(tf.round(pred[0]))]
25
+
26
+ return f"Your dog breed is {pred_class}."
27
+
28
+
29
+ demo = gr.Interface(fn=predict, inputs=gr.Image(shape=(224, 224)), outputs=gr.Label(num_top_classes=3))
30
+
31
+ demo.launch()