Spaces:
Runtime error
Runtime error
Commit
·
d7c64ac
1
Parent(s):
724898b
Update app.py
Browse files
app.py
CHANGED
@@ -1,36 +1,26 @@
|
|
1 |
-
import
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
|
|
14 |
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
],
|
22 |
-
"number",
|
23 |
-
examples=[
|
24 |
-
[5, "add", 3],
|
25 |
-
[4, "divide", 2],
|
26 |
-
[-4, "multiply", 2.5],
|
27 |
-
[0, "subtract", 1.2],
|
28 |
-
[508584894.9485847444, "add", 3000000000.88475775775884],
|
29 |
-
[4, "divide", 2],
|
30 |
-
[-4.585857466363363, "multiply", 6452522522.54754662525646],
|
31 |
-
[0, "subtract", 1.2, "divide", 56635356366.74664],
|
32 |
-
],
|
33 |
-
title="Toy Calculator",
|
34 |
-
description="Here's a sample toy calculator. Allows you to calculate things like $2+2=4$",
|
35 |
-
)
|
36 |
-
demo.launch()
|
|
|
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()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|