cisemh commited on
Commit
cc46505
·
1 Parent(s): 8909c0c

upload files

Browse files
Files changed (2) hide show
  1. app.py +37 -0
  2. requirements.txt +6 -0
app.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ head = (
9
+ "<center>"
10
+ "<img src='file/mnist-classes.png' width=400>"
11
+ "The robot was trained to classify numbers (from 0 to 9). To test it, write your number in the space provided."
12
+ "</center>"
13
+ )
14
+
15
+ ref = "Find the whole code [here](https://github.com/ovh/ai-training-examples/tree/main/apps/gradio/sketch-recognition)."
16
+
17
+ img_size = 28
18
+ labels = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"]
19
+
20
+ model = tf.keras.models.load_model("number_recognition_model_colab.keras")
21
+
22
+
23
+ def predict(img):
24
+
25
+ img = cv2.resize(img, (img_size, img_size))
26
+ img = img.reshape(1, img_size, img_size, 1)
27
+
28
+ preds = model.predict(img)[0]
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()
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ gradio==3.0.10
2
+ tensorflow~=2.18.0
3
+ opencv-python-headless
4
+ numpy~=2.0.2
5
+ opencv-python~=4.10.0.84
6
+ pillow~=11.0.0