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