Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,37 +3,19 @@ import gradio as gr
|
|
3 |
import tensorflow as tf
|
4 |
import numpy as np
|
5 |
|
6 |
-
# Title and description for the interface
|
7 |
-
title = "Welcome to your first sketch recognition app!"
|
8 |
-
head = "<center>The robot was trained to classify numbers (0 to 9). To test it, write your number in the space provided.</center>"
|
9 |
-
|
10 |
|
11 |
# Load the trained model
|
12 |
model = tf.keras.models.load_model("number_recognition_model_colab.keras")
|
13 |
|
14 |
|
15 |
-
def recognize_digit(image):
|
16 |
-
if image is not None:
|
17 |
-
image = image.reshape((1, 28, 28, 1)).astype('float32')/255
|
18 |
-
|
19 |
-
prediction = model.predict(image)
|
20 |
-
|
21 |
-
return {str(i): float(prediction[0][i]) for i in range(10)}
|
22 |
-
else:
|
23 |
-
return ''
|
24 |
-
|
25 |
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
),
|
37 |
-
outputs = gr.Label(num_top_classes=3),
|
38 |
-
live = True
|
39 |
-
).launch(share=True)
|
|
|
3 |
import tensorflow as tf
|
4 |
import numpy as np
|
5 |
|
|
|
|
|
|
|
|
|
6 |
|
7 |
# Load the trained model
|
8 |
model = tf.keras.models.load_model("number_recognition_model_colab.keras")
|
9 |
|
10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
+
def recognize_digit(image):
|
13 |
+
prediction = model.predict(np.reshape(image, (1, 28, 28))).tolist()[0]
|
14 |
+
return {str(i): prediction[i] for i in range(10)}
|
15 |
+
|
16 |
+
sketchpad = gr.Sketchpad(shape=(28, 28))
|
17 |
+
gr.Interface(fn=recognize_digit,
|
18 |
+
inputs=sketchpad,
|
19 |
+
outputs="label",
|
20 |
+
title="Handwritten Digits Classifier",
|
21 |
+
description="This app uses lenet5 for handwritten digits classification").launch()
|
|
|
|
|
|
|
|