Commit
·
1282049
1
Parent(s):
629c68c
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import tensorflow as tf
|
| 2 |
+
import numpy as np
|
| 3 |
+
from urllib.request import urlretrieve
|
| 4 |
+
import gradio as gr
|
| 5 |
+
|
| 6 |
+
urlretrieve("https://gr-models.s3-us-west-2.amazonaws.com/mnist-model.h5", "mnist-model.h5")
|
| 7 |
+
model = tf.keras.models.load_model("mnist-model.h5")
|
| 8 |
+
|
| 9 |
+
def recognize_digit(image):
|
| 10 |
+
image = image.reshape(1, -1) # add a batch dimension
|
| 11 |
+
prediction = model.predict(image).tolist()[0]
|
| 12 |
+
return {str(i): prediction[i] for i in range(10)}
|
| 13 |
+
|
| 14 |
+
gr.Interface(fn=recognize_digit,
|
| 15 |
+
inputs="sketchpad",
|
| 16 |
+
outputs=gr.outputs.Label(num_top_classes=3),
|
| 17 |
+
live=True,
|
| 18 |
+
css=".footer {display:none !important}",
|
| 19 |
+
# title="MNIST Sketchpad",
|
| 20 |
+
description="Draw a number 0 through 9 on the sketchpad, and see predictions in real time.",
|
| 21 |
+
thumbnail="https://raw.githubusercontent.com/gradio-app/real-time-mnist/master/thumbnail2.png").launch();
|
| 22 |
+
|