prithivMLmods commited on
Commit
9a789ee
·
verified ·
1 Parent(s): c986940

Delete fashion_mnist_cloth.py

Browse files
Files changed (1) hide show
  1. fashion_mnist_cloth.py +0 -44
fashion_mnist_cloth.py DELETED
@@ -1,44 +0,0 @@
1
- import gradio as gr
2
- import spaces
3
- from transformers import AutoImageProcessor
4
- from transformers import SiglipForImageClassification
5
- from transformers.image_utils import load_image
6
- from PIL import Image
7
- import torch
8
-
9
- # Load model and processor
10
- model_name = "prithivMLmods/Fashion-Mnist-SigLIP2"
11
- model = SiglipForImageClassification.from_pretrained(model_name)
12
- processor = AutoImageProcessor.from_pretrained(model_name)
13
-
14
- @spaces.GPU
15
- def fashion_mnist_classification(image):
16
- """Predicts fashion category for an image."""
17
- image = Image.fromarray(image).convert("RGB")
18
- inputs = processor(images=image, return_tensors="pt")
19
-
20
- with torch.no_grad():
21
- outputs = model(**inputs)
22
- logits = outputs.logits
23
- probs = torch.nn.functional.softmax(logits, dim=1).squeeze().tolist()
24
-
25
- labels = {
26
- "0": "T-shirt / top", "1": "Trouser", "2": "Pullover", "3": "Dress", "4": "Coat",
27
- "5": "Sandal", "6": "Shirt", "7": "Sneaker", "8": "Bag", "9": "Ankle boot"
28
- }
29
- predictions = {labels[str(i)]: round(probs[i], 3) for i in range(len(probs))}
30
-
31
- return predictions
32
-
33
- # Create Gradio interface
34
- iface = gr.Interface(
35
- fn=fashion_mnist_classification,
36
- inputs=gr.Image(type="numpy"),
37
- outputs=gr.Label(label="Prediction Scores"),
38
- title="Fashion MNIST Classification Labels",
39
- description="Upload an image to classify it into one of the 10 Fashion-MNIST categories."
40
- )
41
-
42
- # Launch the app
43
- if __name__ == "__main__":
44
- iface.launch()