File size: 1,021 Bytes
015495a
a879d14
c905e5e
0b42132
a879d14
0b42132
a879d14
015495a
 
 
 
 
0b42132
 
c905e5e
0b42132
c905e5e
 
0b42132
a879d14
 
 
c905e5e
0b42132
c905e5e
 
ed5d2cb
c905e5e
 
ed5d2cb
 
 
015495a
f3db870
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
# Use a lightweight Python 3.9-slim image
FROM python:3.9-slim

# Set environment variables for Python and Hugging Face cache
ENV PYTHONUNBUFFERED=1
ENV HF_HOME="/tmp/cache/huggingface"

# Accept HF_TOKEN as a build argument and set it as an environment variable
ARG HF_TOKEN
ENV HF_TOKEN=${HF_TOKEN}

# Create a non-root user and switch to that user
RUN useradd -m -u 1000 user
USER user

# Set the working directory
WORKDIR /app

# Copy the requirements file and install dependencies
COPY --chown=user ./requirements.txt /app/requirements.txt
RUN pip install --no-cache-dir --upgrade pip && \
    pip install --no-cache-dir -r /app/requirements.txt

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

# Expose port 7860 (required by Hugging Face Spaces)
EXPOSE 7860

# Optional: Add a label so that Spaces knows which port to use for embedding
LABEL HF_SPACE_PORT=7860

# Start the FastAPI app using uvicorn via python -m
CMD ["python", "-m", "uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]