Spaces:
Runtime error
Runtime error
liquidaudit
commited on
Commit
·
14057b5
1
Parent(s):
f9573f7
init commit
Browse files- app.py +20 -0
- requirements.txt +2 -0
app.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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.").launch();
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
tensorflow==2.3.0
|
| 2 |
+
gradio>=2.2.6
|