Aashiue commited on
Commit
ba9015d
·
1 Parent(s): 59eeead

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -0
app.py CHANGED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+ import torch
4
+ model = torch.hub.load('pytorch/vision:v0.6.0', 'resnet18', pretrained=True).eval()
5
+ import requests
6
+ from PIL import Image
7
+ from torchvision import transforms
8
+
9
+ response = requests.get("https://git.io/JJkYN")
10
+ labels = response.text.split("\n")
11
+
12
+ def predict(inp):
13
+ inp = transforms.ToTensor()(inp).unsqueeze(0)
14
+ with torch.no_grad():
15
+ prediction = torch.nn.functional.softmax(model(inp)[0], dim=0)
16
+ confidences = {labels[i]: float(prediction[i]) for i in range(1000)}
17
+ return confidences
18
+ gr.Interface(fn=predict,
19
+ inputs=gr.Image(type="pil"),
20
+ outputs=gr.Label(num_top_classes=3)).launch()