| FROM python:3.9-slim | |
| WORKDIR /app | |
| # Create directories that the application might need to write to or expect to exist. | |
| # These are created by root during the build. | |
| RUN mkdir -p /app/templates \ | |
| /app/static \ | |
| /app/uploaded_files | |
| # Copy application code | |
| COPY ./app.py /app/ | |
| COPY ./templates/ /app/templates/ | |
| # If you had local static files, you'd copy them here: | |
| # COPY ./static/ /app/static/ | |
| # Grant write permissions to the 'uploaded_files' directory for the user running the app. | |
| # Hugging Face Spaces (and many other container platforms) often run containers | |
| # as a non-root user (e.g., UID 1000). | |
| # We give ownership to user 1000 and group 1000. | |
| # You could also use `chmod -R 777 /app/uploaded_files` but chown is more specific. | |
| RUN chown -R 1000:1000 /app/uploaded_files \ | |
| && chmod -R u+w /app/uploaded_files # Ensure the owner (user 1000) has write permissions | |
| # Install dependencies | |
| RUN pip install --no-cache-dir fastapi "uvicorn[standard]" aiofiles Jinja2 python-multipart | |
| EXPOSE 7860 | |
| CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"] |