File size: 1,570 Bytes
5ce8318
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
FROM python:3.11-slim

# Install git and git-lfs
RUN apt-get update && \
    apt-get install -y git git-lfs && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

# Add a non-root user for better security
RUN useradd -m -u 1000 user

# Switch to non-root user
USER user

# Ensure pip, setuptools, and wheel are up to date
RUN python -m pip install --upgrade pip setuptools wheel

# Set PATH to include user installs
ENV PATH="/home/user/.local/bin:$PATH"

# Set the working directory inside the container
WORKDIR /app

# Copy requirements.txt file and install dependencies
COPY --chown=user ./requirements.txt /app/requirements.txt

# Install only necessary dependencies from the requirements.txt
RUN pip install --no-cache-dir -r /app/requirements.txt

# Create Saved_Model directory and download model from Hugging Face
RUN mkdir -p /app/model && \
    mkdir -p /app/images && \
    cd /app && \
    git lfs install && \
    git clone https://huggingface.co/spaces/dinhanit/triventure_model && \
    cp -r triventure_model/model/* model/ && \
    rm -rf triventure_model

# Create images directory and download images from Hugging Face
RUN cd /app && \
    git clone https://huggingface.co/spaces/dinhanit/triventure_image && \
    cp -r triventure_image/* images/ && \
    rm -rf triventure_image

# Copy the rest of the application code to the working directory
COPY --chown=user . /app

# Expose the port that your app will run on
EXPOSE 7880

# Run the Python script when the container starts
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7880"]