Alen Hovhannisians commited on
Commit
e2a8b14
·
1 Parent(s): 2d237c4
Files changed (3) hide show
  1. app.py +30 -0
  2. mnist_cnn.h5 +3 -0
  3. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import tensorflow as tf
3
+ import numpy as np
4
+ from PIL import Image
5
+
6
+ MODEL_PATH = "mnist_cnn.h5"
7
+
8
+ model = tf.keras.models.load_model(MODEL_PATH)
9
+
10
+ def preprocess(image):
11
+ image = image.convert("L").resize((28, 28))
12
+ img = np.array(image).astype("float32") / 255.0
13
+ img = np.expand_dims(img, axis=-1)
14
+ img = np.expand_dims(img, axis=0)
15
+ return img
16
+
17
+ def predict(image):
18
+ img = preprocess(image)
19
+ preds = model.predict(img)[0]
20
+ return {str(i): float(preds[i]) for i in range(10)}
21
+
22
+ demo = gr.Interface(
23
+ fn=predict,
24
+ inputs=gr.Image(type="pil", label="Draw or upload a digit"),
25
+ outputs=gr.Label(num_top_classes=3),
26
+ title="MNIST Handwritten Digit Classifier",
27
+ description="CNN trained on MNIST to recognize handwritten digits (0–9)."
28
+ )
29
+
30
+ demo.launch()
mnist_cnn.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7f2bc89651d7db9086cb35c55b54f27b32fe42de5985dd3384f7795839a0914b
3
+ size 4368752
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ tensorflow>=2.11
2
+ numpy
3
+ pillow
4
+ gradio