Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,48 +3,30 @@ import gradio as gr
|
|
3 |
import tensorflow as tf
|
4 |
import numpy as np
|
5 |
|
6 |
-
title = "Welcome to your first sketch recognition app!"
|
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 |
-
ref = "Find the whole code [here](https://github.com/ovh/ai-training-examples/tree/main/apps/gradio/sketch-recognition)."
|
13 |
|
14 |
-
img_size = 28
|
15 |
-
labels = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"]
|
16 |
|
17 |
# Model yükleniyor
|
18 |
model = tf.keras.models.load_model("number_recognition_model_colab.keras")
|
19 |
|
20 |
def predict(img):
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
fn=predict,
|
43 |
-
inputs=gr.Sketchpad(label="Draw a number"), # Sketchpad kullanımı
|
44 |
-
outputs=label,
|
45 |
-
title=title,
|
46 |
-
description=head,
|
47 |
-
article=ref
|
48 |
-
)
|
49 |
-
|
50 |
-
interface.launch(debug=True)
|
|
|
3 |
import tensorflow as tf
|
4 |
import numpy as np
|
5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
|
|
|
|
7 |
|
8 |
# Model yükleniyor
|
9 |
model = tf.keras.models.load_model("number_recognition_model_colab.keras")
|
10 |
|
11 |
def predict(img):
|
12 |
+
# Preprocess the input image
|
13 |
+
img = img.reshape(1, 28, 28) / 255.0
|
14 |
+
|
15 |
+
# Make the prediction
|
16 |
+
prediction = model.predict(img)
|
17 |
+
predicted_digit = np.argmax(prediction[0])
|
18 |
+
|
19 |
+
return predicted_digit
|
20 |
+
|
21 |
+
# Create the Gradio interface
|
22 |
+
with gr.Blocks() as demo:
|
23 |
+
gr.Markdown("Welcome on your first sketch recognition app!")
|
24 |
+
|
25 |
+
with gr.Row():
|
26 |
+
sketchpad = gr.Sketchpad(shape=(28, 28))
|
27 |
+
output = gr.Text()
|
28 |
+
|
29 |
+
btn = gr.Button("Submit")
|
30 |
+
btn.click(predict, inputs=sketchpad, outputs=output)
|
31 |
+
|
32 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|