File size: 706 Bytes
e5b9dd4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# Use the official lightweight Python image
FROM python:3.10-slim

# Create a non-root user (Mandatory for Hugging Face Spaces security)
RUN useradd -m -u 1000 user
USER user

# Set environment variables for the user and force model caching to a writable directory
ENV HOME=/home/user \
    PATH=/home/user/.local/bin:$PATH \
    HF_HOME=/tmp/huggingface_cache

WORKDIR $HOME/app

# Copy requirements and install
COPY --chown=user requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# Copy the FastAPI application code
COPY --chown=user . .

# Expose the mandatory Hugging Face port
EXPOSE 7860

# Launch the application
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]