Spaces:
Runtime error
Runtime error
test
Browse files- Dockerfile +1 -1
- main.py +28 -4
- requirements.txt +1 -0
Dockerfile
CHANGED
@@ -10,4 +10,4 @@ RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
|
|
10 |
|
11 |
COPY . .
|
12 |
|
13 |
-
CMD ["
|
|
|
10 |
|
11 |
COPY . .
|
12 |
|
13 |
+
CMD ["python", "main.py"]
|
main.py
CHANGED
@@ -1,7 +1,31 @@
|
|
1 |
-
|
|
|
|
|
|
|
2 |
|
3 |
-
|
|
|
|
|
4 |
|
5 |
|
6 |
-
def
|
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 |
|
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()
|
31 |
+
|
requirements.txt
CHANGED
@@ -14,3 +14,4 @@ wandb
|
|
14 |
protobuf==3.20.1
|
15 |
fastapi==0.74.*
|
16 |
requests==2.27.*
|
|
|
|
14 |
protobuf==3.20.1
|
15 |
fastapi==0.74.*
|
16 |
requests==2.27.*
|
17 |
+
gradio
|