Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
@@ -1,37 +1,29 @@
|
|
1 |
-
import cv2
|
2 |
-
import gradio as gr
|
3 |
-
import tensorflow as tf
|
4 |
-
|
5 |
-
title = "Welcome on your first sketch recognition app!"
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
"
|
10 |
-
"
|
11 |
-
|
12 |
-
|
13 |
-
)
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
return {label: float(pred) for label, pred in zip(labels, preds)}
|
31 |
-
|
32 |
-
label = gr.outputs.Label(num_top_classes=3)
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
interface = gr.Interface(fn=predict, inputs="sketchpad", outputs=label, title=title, description=head, article=ref)
|
37 |
interface.launch()
|
|
|
1 |
+
import cv2
|
2 |
+
import gradio as gr
|
3 |
+
import tensorflow as tf
|
4 |
+
|
5 |
+
title = "Welcome on your first sketch recognition app!"
|
6 |
+
|
7 |
+
head = (
|
8 |
+
"<center>"
|
9 |
+
"The robot was trained to classify numbers (from 0 to 9). To test it, write your number in the space provided."
|
10 |
+
"</center>"
|
11 |
+
)
|
12 |
+
|
13 |
+
ref = "Find the whole code [here](https://github.com/ovh/ai-training-examples/tree/main/apps/gradio/sketch-recognition)."
|
14 |
+
|
15 |
+
img_size = 28
|
16 |
+
labels = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"]
|
17 |
+
|
18 |
+
model = tf.keras.models.load_model("number_recognition_model_colab.keras")
|
19 |
+
|
20 |
+
def predict(img):
|
21 |
+
img = cv2.resize(img, (img_size, img_size))
|
22 |
+
img = img.reshape(1, img_size, img_size, 1)
|
23 |
+
preds = model.predict(img)[0]
|
24 |
+
return {label: float(pred) for label, pred in zip(labels, preds)}
|
25 |
+
|
26 |
+
label = gr.Label(num_top_classes=3)
|
27 |
+
|
28 |
+
interface = gr.Interface(fn=predict, inputs="sketchpad", outputs=label, title=title, description=head, article=ref)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
interface.launch()
|