| # 1. Start with a lightweight Python Linux environment | |
| FROM python:3.9-slim | |
| # 2. Install ffmpeg (Crucial for mobile audio decoding) | |
| RUN apt-get update && apt-get install -y ffmpeg && rm -rf /var/lib/apt/lists/* | |
| # 3. Create a non-root user (Hugging Face requires this for security) | |
| RUN useradd -m -u 1000 user | |
| USER user | |
| ENV PATH="/home/user/.local/bin:$PATH" | |
| # 4. Set the working directory | |
| WORKDIR /app | |
| # 5. Copy your requirements and install them | |
| COPY --chown=user requirements.txt . | |
| RUN pip install --no-cache-dir --upgrade pip && \ | |
| pip install --no-cache-dir -r requirements.txt | |
| # 6. Copy your FastAPI code | |
| COPY --chown=user main.py . | |
| # 7. Start the FastAPI server! | |
| # Hugging Face Spaces strictly require the app to run on port 7860 | |
| CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"] |