i4ata commited on
Commit
8de41e5
·
verified ·
1 Parent(s): dc3c7f1

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +26 -0
  2. pretrained_vit.pth +3 -0
app.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from PIL import Image
3
+ from typing import List, Dict
4
+
5
+ import torch
6
+
7
+ class GradioApp:
8
+ def __init__(self) -> None:
9
+ self.model = torch.load('pretrained_vit.pth', map_location='cpu')
10
+ def predict(self, img_file: str, classes: List[str]) -> Dict[str, float]:
11
+ classes = ['0', '1', '2']
12
+ img = self.model.val_transform(Image.open(img_file)).unsqueeze(0)
13
+ with torch.inference_mode():
14
+ preds = torch.softmax(self.model(img), dim=1)[0].cpu().numpy()
15
+ return {classes[i] : preds[i] for i in range(len(classes))}
16
+ def launch(self):
17
+ demo = gr.Interface(
18
+ fn=self.predict,
19
+ inputs=gr.Image(type='filepath'),
20
+ outputs=gr.Label(num_top_classes=3),
21
+ )
22
+ demo.launch()
23
+
24
+ if __name__ == '__main__':
25
+ app = GradioApp()
26
+ app.launch()
pretrained_vit.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:35925a38eead26593bb6b028900224ef80fe380334cb3c33cb4932af84f5f221
3
+ size 346305720