Upload with huggingface_hub
Browse files- DESCRIPTION.md +1 -0
- README.md +5 -6
- cheetah.jpg +0 -0
- requirements.txt +2 -0
- run.py +23 -0
DESCRIPTION.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
Simple image classification in Pytorch with Gradio's Image input and Label output.
|
README.md
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
colorTo: indigo
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 3.6
|
| 8 |
-
app_file:
|
| 9 |
pinned: false
|
| 10 |
---
|
| 11 |
-
|
| 12 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 1 |
+
|
| 2 |
---
|
| 3 |
+
title: image_classification_main
|
| 4 |
+
emoji: 🔥
|
| 5 |
+
colorFrom: indigo
|
| 6 |
colorTo: indigo
|
| 7 |
sdk: gradio
|
| 8 |
sdk_version: 3.6
|
| 9 |
+
app_file: run.py
|
| 10 |
pinned: false
|
| 11 |
---
|
|
|
|
|
|
cheetah.jpg
ADDED
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
torch
|
| 2 |
+
torchvisionhttps://gradio-main-build.s3.amazonaws.com/c3bec6153737855510542e8154391f328ac72606/gradio-3.6-py3-none-any.whl
|
run.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=[["cheetah.jpg"]],
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
demo.launch()
|