Spaces:
Sleeping
Sleeping
Switch to gradio app
Browse files- Dockerfile +13 -9
- main.py +30 -0
- requirements.txt +4 -0
Dockerfile
CHANGED
@@ -7,23 +7,27 @@ RUN apt-get install -y sudo wget curl nano git \
|
|
7 |
# Create a group and user
|
8 |
ENV APPUSER="appuser"
|
9 |
ENV HOME=/home/$APPUSER
|
10 |
-
RUN
|
11 |
-
useradd -r -u 999 -g appgroup $APPUSER
|
12 |
|
13 |
USER $APPUSER
|
14 |
WORKDIR $HOME
|
15 |
|
16 |
-
|
|
|
|
|
17 |
|
18 |
-
|
|
|
19 |
|
20 |
-
|
21 |
|
22 |
-
|
23 |
|
24 |
-
# Expose port for
|
25 |
-
ENV PORT=
|
26 |
EXPOSE $PORT
|
27 |
|
28 |
# Run streamlit app under conda environment
|
29 |
-
CMD ["sh", "-c", "streamlit run --server.port=$PORT --server.address=0.0.0.0 app.py"]
|
|
|
|
|
|
7 |
# Create a group and user
|
8 |
ENV APPUSER="appuser"
|
9 |
ENV HOME=/home/$APPUSER
|
10 |
+
RUN useradd -m -u 1000 $APPUSER
|
|
|
11 |
|
12 |
USER $APPUSER
|
13 |
WORKDIR $HOME
|
14 |
|
15 |
+
# Set home to the user's home directory
|
16 |
+
ENV HOME=/home/$APPUSER \
|
17 |
+
PATH=/home/$APPUSER/.local/bin:$PATH
|
18 |
|
19 |
+
COPY --chown=$APPUSER ./requirements.txt $HOME/app/requirements.txt
|
20 |
+
WORKDIR $HOME/app
|
21 |
|
22 |
+
RUN pip install --no-cache-dir --user -r requirements.txt
|
23 |
|
24 |
+
COPY --chown=$APPUSER . $HOME/app
|
25 |
|
26 |
+
# Expose port for web service
|
27 |
+
ENV PORT=7860
|
28 |
EXPOSE $PORT
|
29 |
|
30 |
# Run streamlit app under conda environment
|
31 |
+
# CMD ["sh", "-c", "streamlit run --server.port=$PORT --server.address=0.0.0.0 app.py"]
|
32 |
+
|
33 |
+
CMD ["python", "main.py"]
|
main.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
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
torch
|
3 |
+
torchvision
|
4 |
+
requests
|