Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
@@ -1,13 +1,14 @@
|
|
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 |
-
|
9 |
-
|
10 |
-
|
11 |
)
|
12 |
|
13 |
ref = "Find the whole code [here](https://github.com/ovh/ai-training-examples/tree/main/apps/gradio/sketch-recognition)."
|
@@ -17,11 +18,21 @@ labels = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight"
|
|
17 |
|
18 |
model = tf.keras.models.load_model("number_recognition_model_colab.keras")
|
19 |
|
|
|
20 |
def predict(img):
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
|
26 |
label = gr.Label(num_top_classes=3)
|
27 |
|
|
|
1 |
import cv2
|
2 |
import gradio as gr
|
3 |
import tensorflow as tf
|
4 |
+
import numpy as np
|
5 |
|
6 |
title = "Welcome on your first sketch recognition app!"
|
7 |
|
8 |
head = (
|
9 |
+
"<center>"
|
10 |
+
"The robot was trained to classify numbers (from 0 to 9). To test it, write your number in the space provided."
|
11 |
+
"</center>"
|
12 |
)
|
13 |
|
14 |
ref = "Find the whole code [here](https://github.com/ovh/ai-training-examples/tree/main/apps/gradio/sketch-recognition)."
|
|
|
18 |
|
19 |
model = tf.keras.models.load_model("number_recognition_model_colab.keras")
|
20 |
|
21 |
+
|
22 |
def predict(img):
|
23 |
+
# Convert the input image to a NumPy array if needed
|
24 |
+
if not isinstance(img, np.ndarray):
|
25 |
+
img = np.array(img)
|
26 |
+
|
27 |
+
# Print the type and shape of the image
|
28 |
+
print(type(img), img.shape)
|
29 |
+
|
30 |
+
# Resize the image
|
31 |
+
img = cv2.resize(img, (img_size, img_size))
|
32 |
+
img = img.reshape(1, img_size, img_size, 1)
|
33 |
+
preds = model.predict(img)[0]
|
34 |
+
return {label: float(pred) for label, pred in zip(labels, preds)}
|
35 |
+
|
36 |
|
37 |
label = gr.Label(num_top_classes=3)
|
38 |
|