hasibzunair commited on
Commit
6587be0
β€’
1 Parent(s): 66bca24

initial files

Browse files
Files changed (5) hide show
  1. README.md +13 -2
  2. app.py +30 -0
  3. example1.jpg +0 -0
  4. example2.jpg +0 -0
  5. requirements.txt +2 -0
README.md CHANGED
@@ -1,2 +1,13 @@
1
- # image-classifier-gradio-demo
2
- Serve Image classification model with Gradio and Hugging Face Spaces.
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Image Recognition Demo
3
+ emoji: πŸš€
4
+ colorFrom: indigo
5
+ colorTo: pink
6
+ sdk: gradio
7
+ sdk_version: 2.9.4
8
+ app_file: app.py
9
+ pinned: false
10
+ license: afl-3.0
11
+ ---
12
+
13
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces#reference
app.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ import requests
3
+ import gradio as gr
4
+
5
+ from torchvision import transforms
6
+
7
+ """
8
+ Built following https://www.gradio.app/image_classification_in_pytorch/.
9
+ """
10
+
11
+ # Load model
12
+ model = torch.hub.load('pytorch/vision:v0.6.0', 'resnet18', pretrained=True).eval()
13
+
14
+ # Download human-readable labels for ImageNet.
15
+ response = requests.get("https://git.io/JJkYN")
16
+ labels = response.text.split("\n")
17
+
18
+ def predict(inp):
19
+ inp = transforms.ToTensor()(inp).unsqueeze(0)
20
+ with torch.no_grad():
21
+ prediction = torch.nn.functional.softmax(model(inp)[0], dim=0)
22
+ confidences = {labels[i]: float(prediction[i]) for i in range(1000)}
23
+ return confidences
24
+
25
+ gr.Interface(fn=predict,
26
+ inputs=gr.inputs.Image(type="pil"),
27
+ outputs=gr.outputs.Label(num_top_classes=3),
28
+ examples=["example1.jpg", "example2.jpg"],
29
+ theme="default",
30
+ css=".footer{display:none !important}").launch()
example1.jpg ADDED
example2.jpg ADDED
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ torch
2
+ torchvision