cisemh commited on
Commit
f797ca5
·
verified ·
1 Parent(s): 18ffd48

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -36
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
- 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()
 
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()