Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,17 +1,21 @@
|
|
1 |
-
import gradio as gr
|
2 |
import tensorflow as tf
|
3 |
import numpy as np
|
|
|
|
|
4 |
|
5 |
-
|
6 |
-
model = tf.keras.models.load_model("
|
7 |
|
8 |
def recognize_digit(image):
|
9 |
-
|
|
|
10 |
return {str(i): prediction[i] for i in range(10)}
|
11 |
|
12 |
-
sketchpad = gr.Sketchpad(shape=(28, 28))
|
13 |
gr.Interface(fn=recognize_digit,
|
14 |
-
inputs=sketchpad,
|
15 |
-
outputs=
|
16 |
-
|
17 |
-
|
|
|
|
|
|
|
|
|
|
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();
|