# Use an official lightweight Python image FROM python:3.11-slim # Set environment variables # Prevents Python from writing pyc files to disc ENV PYTHONDONTWRITEBYTECODE=1 # Prevents Python from buffering stdout and stderr (helps with logging) ENV PYTHONUNBUFFERED=1 # Set the working directory inside the container WORKDIR /app # Upgrade pip to the latest version RUN pip install --upgrade pip # Copy only the requirements file first to leverage Docker cache # (If requirements.txt doesn't change, Docker won't reinstall dependencies) COPY requirements.txt . # Install Python dependencies RUN pip install --no-cache-dir -r requirements.txt # Copy the rest of the application code COPY app.py . # Expose the port Hugging Face Spaces expects (7860) EXPOSE 7860 # Define default environment variables (you will override these at runtime/deployment) ENV HF_TOKEN="" ENV HF_DATASET_REPO="" # Command to run the FastAPI application using uvicorn CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]