TekamBrice commited on
Commit
6f9709f
·
verified ·
1 Parent(s): 578795a

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -0
app.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ import gradio as gr
3
+
4
+ model = torch.hub.load('pytorch/vision:v0.6.0', 'resnet18', pretrained=True).eval()
5
+ import transformers
6
+ from transformers import pipeline
7
+ from torchvision import transforms
8
+ from PIL import Image
9
+ import requests
10
+ response = requests.get("https://git.io/JJkYN")
11
+ labels = response.text.split("\n")
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
+
20
+ image=gr.Interface(fn=predict,
21
+ inputs=gr.Image(type="pil"),
22
+ outputs=gr.Label(num_top_classes=3),
23
+ ).launch()
24
+
25
+ image