Spaces:
Running
on
A10G
Running
on
A10G
fix: application to Gradio.
Browse files- Dockerfile +1 -1
- main.py +18 -8
- requirements.txt +3 -3
Dockerfile
CHANGED
@@ -25,4 +25,4 @@ WORKDIR $HOME/app
|
|
25 |
# Copy the current directory contents into the container at $HOME/app setting the owner to the user
|
26 |
COPY --chown=user . $HOME/app
|
27 |
|
28 |
-
CMD ["
|
|
|
25 |
# Copy the current directory contents into the container at $HOME/app setting the owner to the user
|
26 |
COPY --chown=user . $HOME/app
|
27 |
|
28 |
+
CMD ["python", "main.py"]
|
main.py
CHANGED
@@ -1,15 +1,25 @@
|
|
1 |
-
from fastapi import FastAPI
|
2 |
import gradio as gr
|
|
|
|
|
|
|
3 |
|
|
|
|
|
|
|
4 |
|
5 |
-
app = FastAPI()
|
6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
-
def greet(name):
|
9 |
-
return "Hello " + name + "!"
|
10 |
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
-
|
13 |
-
def read_root():
|
14 |
-
demo = gr.Interface(fn=greet, inputs="text", outputs="text")
|
15 |
-
demo.launch()
|
|
|
|
|
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 |
+
demo = gr.Interface(
|
20 |
+
fn=predict,
|
21 |
+
inputs=gr.inputs.Image(type="pil"),
|
22 |
+
outputs=gr.outputs.Label(num_top_classes=3),
|
23 |
+
)
|
24 |
|
25 |
+
demo.launch()
|
|
|
|
|
|
requirements.txt
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
fastapi==0.74.*
|
2 |
-
requests==2.27.*
|
3 |
-
uvicorn[standard]==0.17.*
|
4 |
gradio
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
gradio
|
2 |
+
torch
|
3 |
+
torchvision
|
4 |
+
requests
|