Naeem Iqbal commited on
Commit
2b076e2
·
1 Parent(s): 48228ca
app.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoImageProcessor, SiglipForImageClassification
3
+ from transformers.image_utils import load_image
4
+ from PIL import Image
5
+ import torch
6
+
7
+ # Load model and processor
8
+ model_name = "prithivMLmods/Mnist-Digits-SigLIP2"
9
+ model = SiglipForImageClassification.from_pretrained(model_name)
10
+ processor = AutoImageProcessor.from_pretrained(model_name)
11
+
12
+ def classify_digit(image):
13
+ """Predicts the digit in the given handwritten digit image."""
14
+ image = Image.fromarray(image).convert("RGB")
15
+ inputs = processor(images=image, return_tensors="pt")
16
+
17
+ with torch.no_grad():
18
+ outputs = model(**inputs)
19
+ logits = outputs.logits
20
+ probs = torch.nn.functional.softmax(logits, dim=1).squeeze().tolist()
21
+
22
+ labels = {
23
+ "0": "0", "1": "1", "2": "2", "3": "3", "4": "Four",
24
+ "5": "5", "6": "6", "7": "7", "8": "8", "9": "Nine"
25
+ }
26
+ predictions = {labels[str(i)]: round(probs[i], 3) for i in range(len(probs))}
27
+
28
+ return predictions
29
+
30
+ # Create Gradio interface
31
+ iface = gr.Interface(
32
+ fn=classify_digit,
33
+ inputs=gr.Image(type="numpy"),
34
+ outputs=gr.Label(label="Prediction Scores"),
35
+ title="MNIST Digit Classification 🔢",
36
+ description="Upload a handwritten digit image (0-9) to recognize it using MNIST-Digits-SigLIP2."
37
+ )
38
+
39
+ # Launch the app
40
+ if __name__ == "__main__":
41
+ iface.launch()
numNMI/s0.png ADDED
numNMI/s1.png ADDED
numNMI/s2.png ADDED
numNMI/s3.png ADDED
numNMI/s4.png ADDED
numNMI/s5.png ADDED
numNMI/s6.png ADDED
numNMI/s7.png ADDED
numNMI/s8.png ADDED
numNMI/s9.png ADDED
numNMI/test0.png ADDED
numNMI/test1.png ADDED
numNMI/test2.png ADDED
numNMI/test3.png ADDED
numNMI/test4.png ADDED
numNMI/test5.png ADDED
numNMI/test6.png ADDED
numNMI/test7.png ADDED
numNMI/test8.png ADDED
numNMI/test9.png ADDED
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ gradio
2
+ transformers
3
+ torch
4
+ Pillow