File size: 861 Bytes
6f3677b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# ---- Base image ----
FROM python:3.11-slim

# Prevent Python buffering/logging issues
ENV PYTHONDONTWRITEBYTECODE=1 \
    PYTHONUNBUFFERED=1 \
    PORT=7860 \
    HF_HOME=/home/user/.cache/huggingface

# Install system deps
RUN apt-get update && apt-get install -y --no-install-recommends \
    build-essential curl ca-certificates && \
    rm -rf /var/lib/apt/lists/*

# Set workdir
WORKDIR /app

# Install Python deps first (better layer caching)
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# Copy app code
COPY app.py .

# Create a non-root user (optional but recommended)
RUN useradd -m -u 1000 user && chown -R user:users /app
USER user

# Expose the port expected by HF Spaces
EXPOSE 7860

# Start the server
# Uvicorn binds to 0.0.0.0 and PORT env used by Spaces router
CMD uvicorn app:app --host 0.0.0.0 --port ${PORT}