oldgarden21 commited on
Commit
f02bc62
ยท
verified ยท
1 Parent(s): fa3b08a

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -0
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()