uijnbh commited on
Commit
2b42096
·
1 Parent(s): 08df809
Files changed (4) hide show
  1. app.py +26 -0
  2. cheetah.jpg +0 -0
  3. lion.jpg +0 -0
  4. requirements.txt +1 -0
app.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+
3
+ model = torch.hub.load('pytorch/vision:v0.6.0', 'resnet18', pretrained=True).eval()
4
+
5
+ import requests
6
+ from torchvision import transforms
7
+
8
+ # Download human-readable labels for ImageNet.
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
+
19
+ import gradio as gr
20
+
21
+ gr.Interface(fn=predict,
22
+ inputs=gr.inputs.Image(type="pil"),
23
+ outputs=gr.outputs.Label(num_top_classes=3),
24
+ examples=["lion.jpg", "cheetah.jpg"],
25
+ theme="default",
26
+ css=".footer{display:none !important}").launch()
cheetah.jpg ADDED
lion.jpg ADDED
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ torch