HeenaPatel commited on
Commit
849e72d
·
1 Parent(s): ff53d5a
Files changed (3) hide show
  1. app.py +4 -20
  2. app2.py +0 -7
  3. app_classification.py +23 -0
app.py CHANGED
@@ -1,23 +1,7 @@
1
  import gradio as gr
2
- import torch
3
- import requests
4
- from torchvision import transforms
5
 
6
- model = torch.hub.load('pytorch/vision:v0.6.0', 'resnet18', pretrained=True).eval()
7
- response = requests.get("https://git.io/JJkYN")
8
- labels = response.text.split("\n")
9
 
10
- def predict(inp):
11
- inp = transforms.ToTensor()(inp).unsqueeze(0)
12
- with torch.no_grad():
13
- prediction = torch.nn.functional.softmax(model(inp)[0], dim=0)
14
- confidences = {labels[i]: float(prediction[i]) for i in range(1000)}
15
- return confidences
16
-
17
- demo = gr.Interface(fn=predict,
18
- inputs=gr.inputs.Image(type="pil"),
19
- outputs=gr.outputs.Label(num_top_classes=3),
20
- examples=[["dog.jpg"]],
21
- )
22
-
23
- demo.launch()
 
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
+ iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
app2.py DELETED
@@ -1,7 +0,0 @@
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
- iface.launch()
 
 
 
 
 
 
 
 
app_classification.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ import requests
4
+ from torchvision import transforms
5
+
6
+ model = torch.hub.load('pytorch/vision:v0.6.0', 'resnet18', pretrained=True).eval()
7
+ response = requests.get("https://git.io/JJkYN")
8
+ labels = response.text.split("\n")
9
+
10
+ def predict(inp):
11
+ inp = transforms.ToTensor()(inp).unsqueeze(0)
12
+ with torch.no_grad():
13
+ prediction = torch.nn.functional.softmax(model(inp)[0], dim=0)
14
+ confidences = {labels[i]: float(prediction[i]) for i in range(1000)}
15
+ return confidences
16
+
17
+ demo = gr.Interface(fn=predict,
18
+ inputs=gr.inputs.Image(type="pil"),
19
+ outputs=gr.outputs.Label(num_top_classes=3),
20
+ examples=[["dog.jpg"]],
21
+ )
22
+
23
+ demo.launch()