File size: 2,473 Bytes
5478d4e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57328cd
5478d4e
 
 
 
 
 
 
 
 
26827e4
5478d4e
 
 
 
 
 
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
FROM python:3.9

# Set working directory inside the container
WORKDIR /app

# Reduce Docker image size by cleaning up unused files
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* ~/.cache/

# Install system dependencies
RUN apt-get update && apt-get install -y \
    libgl1-mesa-glx libglib2.0-0 fontconfig \
    git wget ffmpeg && \
    rm -rf /var/lib/apt/lists/*

# Copy entrypoint script and make it executable
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh

# Create non-root user
RUN useradd -m -u 1000 user
USER root
ENV HOME=/home/user

# Install Python dependencies
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt

# Install Hugging Face CLI + required ML dependencies (hf_hub is at 0.14.1 and may cause a crash)
RUN pip install --no-cache-dir "huggingface_hub>=0.16.0,<0.21.0" --extra-index-url "https://download.pytorch.org/whl/cpu"
    
# Install LoveDA repository dependencies (last line ignore error flag on)
RUN git clone https://github.com/Junjue-Wang/LoveDA.git /home/user/LoveDA
WORKDIR /home/user/LoveDA
RUN pip install --no-cache-dir -r requirements.txt || true 

# Return to working dir
WORKDIR $HOME/app

# Ensure Hugging Face CLI is accessible
ENV PATH="/home/user/.local/bin:$PATH"

# Create model/cache folders
RUN mkdir -p /home/user/app/model /home/user/app/cache/uploads && \
    chown -R user:user /home/user/app && chmod -R 777 /home/user/app

# Switch back to non-root user
USER user
WORKDIR $HOME/app

# Copy application source code
COPY --chown=user . $HOME/app

# Pre-download all Hugging Face models
RUN python -c "from huggingface_hub import snapshot_download; snapshot_download(repo_id='facebook/detr-resnet-50', local_dir='/home/user/app/model/detr', local_dir_use_symlinks=False)"
RUN wget -O $HOME/app/model/garbage_detector.pt https://huggingface.co/BinKhoaLe1812/Garbage_Detection/resolve/main/garbage_detector.pt
RUN wget -O $HOME/app/model/yolov5-detect-trash-classification.pt https://huggingface.co/turhancan97/yolov5-detect-trash-classification/resolve/main/yolov5s.pt
RUN wget -O /home/user/app/model/yolov8n.pt https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8n.pt

# Verify model setup
RUN python setup.py

# Clean outputs folder
RUN rm -rf /home/user/app/outputs/*.mp4

# Copy static images
COPY sprite.png /home/user/app/sprite.png
# COPY icon.png /home/user/app/icon.png

# Expose FastAPI port
EXPOSE 7860

# Start app
ENTRYPOINT ["/entrypoint.sh"]