# Use a lightweight Python base image FROM python:3.10-slim # Hugging Face Spaces require applications to run as a non-root user for security. # We create a user named 'user' with User ID 1000. RUN useradd -m -u 1000 user # Switch to that new user USER user # Set environment variables for the user's home and path ENV HOME=/home/user \ PATH=/home/user/.local/bin:$PATH # Set the working directory inside the container WORKDIR $HOME/app # Copy the requirements file FIRST, and make sure the new user owns it COPY --chown=user requirements.txt . # Install all the Python libraries RUN pip install --no-cache-dir -r requirements.txt # Copy the rest of your application files (app.py and the weights file) COPY --chown=user . . # Expose the port Gradio will run on EXPOSE 7860 # Force Gradio to broadcast on all network interfaces ENV GRADIO_SERVER_NAME="0.0.0.0" ENV GRADIO_SERVER_PORT="7860" # Command to boot up the production engine # Boot up the FastAPI server via Uvicorn CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]