Spaces:
Runtime error
Runtime error
Upload with huggingface_hub
Browse files
README.md
CHANGED
@@ -6,6 +6,6 @@ colorFrom: indigo
|
|
6 |
colorTo: indigo
|
7 |
sdk: gradio
|
8 |
sdk_version: 3.4.1
|
9 |
-
app_file:
|
10 |
pinned: false
|
11 |
---
|
|
|
6 |
colorTo: indigo
|
7 |
sdk: gradio
|
8 |
sdk_version: 3.4.1
|
9 |
+
app_file: run.py
|
10 |
pinned: false
|
11 |
---
|
run.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
from urllib.request import urlretrieve
|
3 |
+
|
4 |
+
import tensorflow as tf
|
5 |
+
|
6 |
+
import gradio
|
7 |
+
import gradio as gr
|
8 |
+
|
9 |
+
urlretrieve(
|
10 |
+
"https://gr-models.s3-us-west-2.amazonaws.com/mnist-model.h5", "mnist-model.h5"
|
11 |
+
)
|
12 |
+
model = tf.keras.models.load_model("mnist-model.h5")
|
13 |
+
|
14 |
+
|
15 |
+
def recognize_digit(image):
|
16 |
+
image = image.reshape(1, -1)
|
17 |
+
prediction = model.predict(image).tolist()[0]
|
18 |
+
return {str(i): prediction[i] for i in range(10)}
|
19 |
+
|
20 |
+
|
21 |
+
im = gradio.Image(shape=(28, 28), image_mode="L", invert_colors=False, source="canvas")
|
22 |
+
|
23 |
+
demo = gr.Interface(
|
24 |
+
recognize_digit,
|
25 |
+
im,
|
26 |
+
gradio.Label(num_top_classes=3),
|
27 |
+
live=True,
|
28 |
+
interpretation="default",
|
29 |
+
capture_session=True,
|
30 |
+
)
|
31 |
+
|
32 |
+
if __name__ == "__main__":
|
33 |
+
demo.launch()
|