Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from huggingface_hub import hf_hub_download
|
| 3 |
+
import tensorflow as tf
|
| 4 |
+
|
| 5 |
+
# Hugging Face Hub์์ ๋ชจ๋ธ ํ์ผ ๋ค์ด๋ก๋
|
| 6 |
+
model_path = hf_hub_download(repo_id="safoinme/zenml-mnist", filename="model.h5")
|
| 7 |
+
|
| 8 |
+
# ๋ค์ด๋ก๋ํ ๋ชจ๋ธ ํ์ผ๋ก๋ถํฐ Keras ๋ชจ๋ธ ๋ก๋
|
| 9 |
+
model = tf.keras.models.load_model(model_path)
|
| 10 |
+
|
| 11 |
+
def recognize_digit(img):
|
| 12 |
+
# ์ด๋ฏธ์ง ์ ์ฒ๋ฆฌ
|
| 13 |
+
img = img.reshape(1, 28, 28, 1) / 255.0
|
| 14 |
+
# ๋ชจ๋ธ ์์ธก
|
| 15 |
+
prediction = model.predict(img).argmax()
|
| 16 |
+
return str(prediction)
|
| 17 |
+
|
| 18 |
+
# Gradio ์ธํฐํ์ด์ค ์ค์
|
| 19 |
+
iface = gr.Interface(fn=recognize_digit,
|
| 20 |
+
inputs=gr.inputs.Image(shape=(28,28), image_mode='L', invert_colors=True, source="canvas"),
|
| 21 |
+
outputs="text",
|
| 22 |
+
title="MNIST Digit Recognizer",
|
| 23 |
+
description="Draw a digit on the canvas and click 'Submit' to recognize it. Model trained on the MNIST dataset.")
|
| 24 |
+
# ์ธํฐํ์ด์ค ์คํ
|
| 25 |
+
iface.launch()
|