File size: 1,485 Bytes
32bb925
03fa7b1
 
32bb925
03fa7b1
 
32bb925
 
03fa7b1
32bb925
bd5db9c
03fa7b1
 
bd5db9c
03fa7b1
bd5db9c
ae576f9
 
03fa7b1
 
32bb925
03fa7b1
 
32bb925
03fa7b1
32bb925
 
 
03fa7b1
32bb925
03fa7b1
32bb925
03fa7b1
 
32bb925
 
 
 
 
03fa7b1
 
32bb925
03fa7b1
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
# Use a slim Python base image
FROM python:3.11-slim

# Set environment variables to prevent bytecode generation and buffer output
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
# Set Hugging Face cache directory
ENV HF_HOME=/app/hf_cache

# Install system dependencies required for OpenCV and other libraries
RUN apt-get update && apt-get install -y --no-install-recommends \
    git \
    ffmpeg \
    libgl1-mesa-glx \
    libglib2.0-0 \
    build-essential \
    curl \
    wget \
    && rm -rf /var/lib/apt/lists/*

# Set the working directory
WORKDIR /app

# Copy the requirements file
COPY requirements.txt .

# Install Python dependencies, ensuring we get the CPU-only version of PyTorch
# This significantly reduces the Docker image size and is crucial for CPU-only environments
RUN pip install --upgrade pip
RUN pip install --no-cache-dir -r requirements.txt --extra-index-url https://download.pytorch.org/whl/cpu

# Copy the rest of the application code
COPY . .

# Pre-download the model weights during the build process
# This prevents downloading the model every time the container starts, leading to faster startup
RUN python -c "from huggingface_hub import hf_hub_download; hf_hub_download(repo_id='eugenesiow/real-esrgan', filename='RealESRGAN_x4plus.pth', cache_dir=None, local_dir='./weights')"

# Expose the port the app will run on
EXPOSE 8000

# Command to run the application using uvicorn
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8000"]