ajinkyakolhe112 commited on
Commit
caf6be1
·
verified ·
1 Parent(s): 70e5abd

Update app.py

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