Spaces:
Sleeping
Sleeping
switch to gradio
Browse files- Dockerfile +1 -1
- app.py +30 -0
- requirements.txt +2 -1
Dockerfile
CHANGED
@@ -43,4 +43,4 @@ WORKDIR $HOME/app
|
|
43 |
|
44 |
# COPY . .
|
45 |
|
46 |
-
CMD ["
|
|
|
43 |
|
44 |
# COPY . .
|
45 |
|
46 |
+
CMD ["python", "app.py"]
|
app.py
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
|
11 |
+
def predict(inp):
|
12 |
+
inp = transforms.ToTensor()(inp).unsqueeze(0)
|
13 |
+
with torch.no_grad():
|
14 |
+
prediction = torch.nn.functional.softmax(model(inp)[0], dim=0)
|
15 |
+
confidences = {labels[i]: float(prediction[i]) for i in range(1000)}
|
16 |
+
return confidences
|
17 |
+
|
18 |
+
|
19 |
+
def run():
|
20 |
+
demo = gr.Interface(
|
21 |
+
fn=predict,
|
22 |
+
inputs=gr.inputs.Image(type="pil"),
|
23 |
+
outputs=gr.outputs.Label(num_top_classes=3),
|
24 |
+
)
|
25 |
+
|
26 |
+
demo.launch(server_name="0.0.0.0", server_port=7860)
|
27 |
+
|
28 |
+
|
29 |
+
if __name__ == "__main__":
|
30 |
+
run()
|
requirements.txt
CHANGED
@@ -5,4 +5,5 @@ torch==1.11.*
|
|
5 |
transformers==4.*
|
6 |
uvicorn[standard]==0.17.*
|
7 |
--extra-index-url https://download.pytorch.org/whl/cu113
|
8 |
-
|
|
|
|
5 |
transformers==4.*
|
6 |
uvicorn[standard]==0.17.*
|
7 |
--extra-index-url https://download.pytorch.org/whl/cu113
|
8 |
+
torchvision
|
9 |
+
gradio
|