Adding of custom Docker file and updating pip tools before installing
Browse files- Dockerfile +44 -0
- app.py +2 -1
- requirements.txt +1 -1
Dockerfile
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Use a lightweight Python image with version 3.9
|
2 |
+
FROM python:3.9-slim
|
3 |
+
|
4 |
+
# Create a non-root user with UID 1000 as required by Hugging Face Spaces
|
5 |
+
RUN useradd -m -u 1000 user
|
6 |
+
|
7 |
+
# Set environment variables
|
8 |
+
ENV PYTHONDONTWRITEBYTECODE=1 \
|
9 |
+
PYTHONUNBUFFERED=1 \
|
10 |
+
PATH="/home/user/.local/bin:$PATH"
|
11 |
+
|
12 |
+
# Install required system packages (including wget)
|
13 |
+
RUN apt-get update && apt-get install -y wget && rm -rf /var/lib/apt/lists/*
|
14 |
+
|
15 |
+
RUN apt-get update && apt-get install -y git
|
16 |
+
RUN git config --global user.email "Mojmir@users.noreply.huggingface.co"
|
17 |
+
# Switch to non-root user
|
18 |
+
USER user
|
19 |
+
|
20 |
+
# Set the working directory (root, since you don’t have an /app folder)
|
21 |
+
WORKDIR /home/user
|
22 |
+
|
23 |
+
# Copy requirements.txt before copying other files to utilize Docker cache
|
24 |
+
COPY --chown=user requirements.txt .
|
25 |
+
|
26 |
+
# pip update install tools
|
27 |
+
run pip install -U pip setuptools wheel
|
28 |
+
# Install required dependencies
|
29 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
30 |
+
|
31 |
+
# Copy the rest of the project files to the container
|
32 |
+
COPY --chown=user . .
|
33 |
+
|
34 |
+
# RUN wget https://github.com/gitpod-io/openvscode-server/releases/download/openvscode-server-v1.86.2/openvscode-server-v1.86.2-linux-x64.tar.gz -O /tmp/openvscode-server.tar.gz && \
|
35 |
+
# tar -xzf /tmp/openvscode-server.tar.gz -C /opt && \
|
36 |
+
# rm /tmp/openvscode-server.tar.gz && \
|
37 |
+
# mv /opt/openvscode-server-v1.86.2-linux-x64 /opt/openvscode-server && \
|
38 |
+
# chown -R 1000:1000 /opt/openvscode-server
|
39 |
+
|
40 |
+
# Expose the port Gradio runs on (7860)
|
41 |
+
# EXPOSE 7860
|
42 |
+
|
43 |
+
# Command to run the Gradio app
|
44 |
+
CMD ["python", "app.py"]
|
app.py
CHANGED
@@ -4,6 +4,8 @@ import torch.nn as nn
|
|
4 |
from torchvision import transforms
|
5 |
from PIL import Image
|
6 |
import time
|
|
|
|
|
7 |
from concrete.ml.torch.compile import compile_torch_model
|
8 |
|
9 |
from custom_resnet import resnet18_custom # Assuming custom_resnet.py is in the same directory
|
@@ -21,7 +23,6 @@ def load_model(model_path, device):
|
|
21 |
model.eval() # Set model to evaluation mode
|
22 |
return model
|
23 |
|
24 |
-
from concrete.fhe import Configuration
|
25 |
|
26 |
def load_secure_model(model):
|
27 |
print("Compiling secure model...")
|
|
|
4 |
from torchvision import transforms
|
5 |
from PIL import Image
|
6 |
import time
|
7 |
+
|
8 |
+
from concrete.fhe import Configuration
|
9 |
from concrete.ml.torch.compile import compile_torch_model
|
10 |
|
11 |
from custom_resnet import resnet18_custom # Assuming custom_resnet.py is in the same directory
|
|
|
23 |
model.eval() # Set model to evaluation mode
|
24 |
return model
|
25 |
|
|
|
26 |
|
27 |
def load_secure_model(model):
|
28 |
print("Compiling secure model...")
|
requirements.txt
CHANGED
@@ -2,4 +2,4 @@ gradio
|
|
2 |
torch
|
3 |
torchvision
|
4 |
Pillow
|
5 |
-
concrete-ml
|
|
|
2 |
torch
|
3 |
torchvision
|
4 |
Pillow
|
5 |
+
concrete-ml==1.6.1
|