File size: 1,059 Bytes
a4c8c42
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# Use the official Python 3.9 slim image
FROM python:3.9-slim

# Create a user with UID 1000 (Required for Hugging Face Spaces security)
RUN useradd -m -u 1000 user
USER user

# Add local bin to PATH to ensure pip installed packages are found
ENV PATH="/home/user/.local/bin:$PATH"

# Set the working directory
WORKDIR /app

# Copy the requirements file first to leverage Docker cache
COPY --chown=user ./requirements.txt requirements.txt

# Step 1: Install PyTorch CPU version specifically (to save space and fix compatibility)
# We use torch 2.4.0 to resolve conflicts with newer transformers libraries
RUN pip install --no-cache-dir torch==2.4.0 --index-url https://download.pytorch.org/whl/cpu

# Step 2: Install the rest of the dependencies from requirements.txt
RUN pip install --no-cache-dir -r requirements.txt

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

# Expose the port used by Hugging Face Spaces
EXPOSE 7860

# Command to start the application using Uvicorn
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]