File size: 952 Bytes
4396349
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8204b3d
 
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
# 1. Base Image: Python 3.9 Slim (Small & Fast)
FROM python:3.9-slim

# 2. Set Working Directory inside container
WORKDIR /code

# 3. Copy Requirements first (optimizes build cache)
COPY ./requirements.txt /code/requirements.txt

# 4. Install Dependencies
# --no-cache-dir keeps the image small
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt

# 5. Set up the "user" (Hugging Face Security Requirement)
# Spaces requires the app to run as user ID 1000, not root.
RUN useradd -m -u 1000 user

# Switch to non-root user
USER user
ENV HOME=/home/user \
    PATH=/home/user/.local/bin:$PATH

# 6. Copy the rest of the application code
# --chown=user ensures the non-root user owns the files
COPY --chown=user . /code

# 7. Expose the standard Spaces port
EXPOSE 7860

# 8. Start the API
# CRITICAL FIX: "main:app" matches your file structure where main.py is at the root
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]