Spaces:
Sleeping
Sleeping
| # Use an official Python runtime as the base image | |
| # This image contains Python 3.9 and is a lightweight slim version to minimize image size | |
| FROM python:3.9-slim | |
| # Set the working directory inside the container | |
| # All subsequent commands will run in this /app directory | |
| WORKDIR /app | |
| # Copy the local files into the container | |
| # Copies everything from the current directory on the host machine to /app in the container | |
| COPY . /app | |
| # Set environment variable for Hugging Face cache directory | |
| # This helps set a custom cache location for Hugging Face models and datasets | |
| ENV HF_HOME=/app/.cache | |
| # Create the necessary cache directories for Hugging Face | |
| # This ensures that Hugging Face has the required directories set up for caching | |
| RUN mkdir -p /app/.cache/huggingface/hub && \ | |
| chmod -R 777 /app/.cache && \ | |
| chmod -R 777 /app/.cache/huggingface | |
| # Upgrade pip to the latest version | |
| # This ensures you are using the most up-to-date version of pip for installing dependencies | |
| RUN pip install --upgrade pip | |
| # Install the dependencies listed in requirements.txt | |
| # The --no-cache-dir flag ensures pip does not use or store cached versions of packages, saving space | |
| RUN pip install --no-cache-dir -r requirements.txt | |
| # Copy the requirements.txt file with ownership changes | |
| # --chown=user ensures that the requirements.txt file inside the container is owned by a specific user (e.g., user) for security and permissions | |
| COPY --chown=user ./requirements.txt requirements.txt | |
| # Reinstall dependencies from the requirements.txt | |
| # Installing again to ensure the dependencies are properly set with the correct ownership and permissions | |
| RUN pip install --no-cache-dir --upgrade -r requirements.txt | |
| # Expose the port the app will run on | |
| # FastAPI typically runs on port 8000, but we’re using 7860 in this case | |
| EXPOSE 7860 | |
| # Command to run the application using uvicorn | |
| # Uvicorn is an ASGI server that runs the FastAPI app | |
| # --host 0.0.0.0 makes the app accessible to any IP address, so it's reachable from outside the container | |
| # --port 7860 sets the port number on which the FastAPI app will be available | |
| CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"] | |