orossant commited on
Commit
6b5d1fc
1 Parent(s): 65a3c00

Upload 3 files

Browse files

add application and 2 sample pictures

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