Spaces:
Sleeping
Sleeping
| # Use Python 3.9 as the base image | |
| FROM python:3.9 | |
| # Set working directory in the container | |
| WORKDIR /app | |
| # Create a non-root user and set permissions | |
| RUN useradd -m myuser && chown -R myuser:myuser /app | |
| USER myuser | |
| # Set Hugging Face cache directory | |
| ENV HF_HOME=/app/.cache/huggingface | |
| # Update PATH to include user’s local bin (where pip installs uvicorn) | |
| ENV PATH="/home/myuser/.local/bin:${PATH}" | |
| # Copy requirements.txt and install dependencies | |
| COPY --chown=myuser:myuser requirements.txt . | |
| RUN pip install --no-cache-dir -r requirements.txt | |
| # Explicitly install uvicorn to ensure it’s available | |
| RUN pip install --no-cache-dir uvicorn | |
| # Pre-download the model to avoid runtime issues | |
| RUN python -c "from transformers import pipeline; pipeline('text-classification', model='roberta-base-openai-detector')" | |
| # Copy the application code | |
| COPY --chown=myuser:myuser . . | |
| # Run the FastAPI app with Uvicorn | |
| CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"] |