Spaces:
Sleeping
Sleeping
Commit
·
7481ae6
1
Parent(s):
25a44a2
Gradio interface for testing the model
Browse files
app.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import tensorflow as tf
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
model = tf.keras.models.load_model('model.h5')
|
5 |
+
|
6 |
+
def recognize_digit(image):
|
7 |
+
if image is not None:
|
8 |
+
image = image.reshape((1, 28, 28, 1)) / 255.0
|
9 |
+
prediction = model.predict(image)
|
10 |
+
|
11 |
+
return {str(i): float(prediction[0][i]) for i in range(10)}
|
12 |
+
else:
|
13 |
+
return ''
|
14 |
+
|
15 |
+
iface = gr.Interface(
|
16 |
+
fn=recognize_digit,
|
17 |
+
inputs=gr.Image(
|
18 |
+
shape=(28, 28),
|
19 |
+
image_mode='L',
|
20 |
+
invert_colors=True,
|
21 |
+
source='canvas'
|
22 |
+
),
|
23 |
+
outputs=gr.Label(num_top_classes=3),
|
24 |
+
live=True
|
25 |
+
)
|
26 |
+
|
27 |
+
iface.launch(share=True)
|