Spaces:
Sleeping
Sleeping
| # Use a recent, slim Python base image | |
| FROM python:3.10-slim | |
| # Set the working directory in the container | |
| WORKDIR /app | |
| # Prevent Python from writing pyc files to disc (optional but good practice) | |
| ENV PYTHONDONTWRITEBYTECODE 1 | |
| # Ensure Python output is sent straight to terminal (useful for logs) | |
| ENV PYTHONUNBUFFERED 1 | |
| # Upgrade pip | |
| RUN python -m pip install --upgrade pip | |
| # Copy the requirements file into the container | |
| # This file should list all necessary Python packages for the project. | |
| COPY requirements.txt . | |
| # Install dependencies | |
| # --no-cache-dir reduces image size, beneficial for smaller final images. | |
| # --default-timeout=100 increases timeout for pip install (can be adjusted if needed). | |
| RUN pip install --no-cache-dir --default-timeout=100 -r requirements.txt | |
| # Copy the application code into the container | |
| # This assumes your FastAPI application is in a file named 'main.py'. | |
| COPY api.py . | |
| # If you had other local modules or directories part of your project (e.g., a 'core' or 'utils' folder), | |
| # you would add more COPY lines here, like: | |
| # COPY ./your_module_directory ./your_module_directory | |
| # Expose the port the app runs on. | |
| # This should match the port Uvicorn is configured to use in the CMD instruction. | |
| EXPOSE 7860 | |
| # Command to run the Uvicorn server | |
| # It will look for an ASGI application instance named 'app' in the 'main.py' file. | |
| # Runs on port 7860 and listens on all available network interfaces (0.0.0.0). | |
| # Note: For production environments, ensure --reload is NOT used as it's for development. | |
| CMD ["uvicorn", "api:app", "--host", "0.0.0.0", "--port", "7860"] |