raihanp commited on
Commit
98fe69e
·
verified ·
1 Parent(s): 93120f2

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -0
app.py ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from PIL import Image
2
+ import torch
3
+ import gradio as gr
4
+
5
+ inference = torch.load('fine_tune_resnet.pth')
6
+ inference.eval()
7
+
8
+ def classifier(image):
9
+ output = inference(test_transform(Image.open('/content/1000-ml-plastic-water-bottle-500x500.webp')).unsqueeze(0))
10
+ _, prediction = torch.max(output,1)
11
+ confidence = round(torch.softmax(output,1).max().item(),4)*100
12
+
13
+ return f'{label_dict[prediction.item()]} (Confidence: {confidence}%)'
14
+
15
+ iface = gr.Interface(fc=classifier,
16
+ inputs=gr.Image(type="pil"),
17
+ outputs='text')
18
+ iface.launch(share=True)