moshel commited on
Commit
be366e7
·
1 Parent(s): 781ba9f

image classification

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