# Dockerfile # This Dockerfile builds the environment for your FastAPI application on Hugging Face Spaces. # Use a lightweight Python base image FROM python:3.10-slim # Create a non-root user and switch to it for security RUN useradd -m -u 1000 user USER user # Set the PATH environment variable to include the user's local bin directory # This ensures executables installed via pip (like uvicorn) are found ENV PATH="/home/user/.local/bin:$PATH" # Set environment variables to prevent Python from buffering stdout/stderr ENV PYTHONUNBUFFERED 1 # IMPORTANT FIX: Set Hugging Face cache directory to a writable location ENV HF_HOME=/app/hf_cache # Copy requirements.txt and install dependencies # This step is done separately to leverage Docker's layer caching COPY --chown=user requirements.txt . RUN pip install --no-cache-dir --upgrade pip && \ pip install --no-cache-dir -r requirements.txt # Copy the rest of your application code into the container # This includes app.py, translate_api.py, __init__.py, etc. COPY --chown=user . /app # Expose the port that the FastAPI application will listen on EXPOSE 7860 # --- MODIFIED CMD COMMAND --- # Explicitly add the current working directory to PYTHONPATH # Then run uvicorn. This helps ensure Python finds 'translation_api' module. CMD ["bash", "-c", "PYTHONPATH=/app:$PYTHONPATH uvicorn app:app --host 0.0.0.0 --port 7860"]