NOABOL35631y commited on
Commit
d7c64ac
·
1 Parent(s): 724898b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -34
app.py CHANGED
@@ -1,36 +1,26 @@
1
- import gradio as gr
 
 
 
 
 
2
 
3
- def calculator(num1, operation, num2, operation, num3):
4
- if operation == "add":
5
- return num1 + num2 + num3
6
- elif operation == "subtract":
7
- return num1 - num2 - num3
8
- elif operation == "multiply":
9
- return num1 * num2 * num3
10
- elif operation == "divide":
11
- if num2 == 0:
12
- raise gr.Error("Cannot divide by zero!")
13
- return num1 / num2 / num3
 
14
 
15
- demo = gr.Interface(
16
- calculator,
17
- [
18
- "number",
19
- gr.Radio(["add", "subtract", "multiply", "divide"]),
20
- "number"
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()