shravvvv commited on
Commit
0f79521
·
1 Parent(s): 3fba168

Added app.py

Browse files
Files changed (2) hide show
  1. app.py +35 -0
  2. requirements.txt +12 -0
app.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ from PIL import Image
4
+ from transformers import AutoModelForImageClassification, AutoImageProcessor
5
+
6
+ # Load model and processor
7
+ model = AutoModelForImageClassification.from_pretrained("shravvvv/SAG-ViT")
8
+ processor = AutoImageProcessor.from_pretrained("shravvvv/SAG-ViT")
9
+
10
+ # CIFAR-10 class labels
11
+ class_labels = [
12
+ 'airplane', 'automobile', 'bird', 'cat', 'deer',
13
+ 'dog', 'frog', 'horse', 'ship', 'truck'
14
+ ]
15
+
16
+ # Define prediction function
17
+ def predict(image):
18
+ inputs = processor(images=image, return_tensors="pt")
19
+ with torch.no_grad():
20
+ outputs = model(**inputs)
21
+ logits = outputs.logits
22
+ predicted_class_idx = logits.argmax(-1).item()
23
+ return class_labels[predicted_class_idx]
24
+
25
+ # Create Gradio interface
26
+ iface = gr.Interface(
27
+ fn=predict,
28
+ inputs=gr.inputs.Image(type="pil"),
29
+ outputs=gr.outputs.Label(),
30
+ title="SAG-ViT Image Classifier",
31
+ description="Upload an image to classify it using the SAG-ViT model."
32
+ )
33
+
34
+ if __name__ == "__main__":
35
+ iface.launch()
requirements.txt ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ numpy==1.26.4
2
+ pandas==2.2.3
3
+ matplotlib==3.7.5
4
+ seaborn==0.12.2
5
+ tqdm==4.66.4
6
+ psutil==5.9.3
7
+ pynvml==11.4.1
8
+ scikit-learn==1.2.2
9
+ torch==2.4.0
10
+ torch-geometric==2.6.1
11
+ torchvision==0.19.0
12
+ networkx==3.3