Spaces:
Sleeping
Sleeping
Subha Nawer Pushpita
commited on
Commit
·
aebbe04
1
Parent(s):
cb1e716
delete initial app.py
Browse files
app.py
DELETED
|
@@ -1,24 +0,0 @@
|
|
| 1 |
-
import torch
|
| 2 |
-
import requests
|
| 3 |
-
import gradio as gr
|
| 4 |
-
from PIL import Image
|
| 5 |
-
from torchvision import transforms
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
model = torch.hub.load('pytorch/vision:v0.6.0', 'resnet18', pretrained=True).eval()
|
| 9 |
-
|
| 10 |
-
# Download human-readable labels for ImageNet.
|
| 11 |
-
response = requests.get("https://git.io/JJkYN")
|
| 12 |
-
labels = response.text.split("\n")
|
| 13 |
-
|
| 14 |
-
def predict(inp):
|
| 15 |
-
inp = transforms.ToTensor()(inp).unsqueeze(0)
|
| 16 |
-
with torch.no_grad():
|
| 17 |
-
prediction = torch.nn.functional.softmax(model(inp)[0], dim=0)
|
| 18 |
-
confidences = {labels[i]: float(prediction[i]) for i in range(1000)}
|
| 19 |
-
return confidences
|
| 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"]).launch(share=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|