generate_api / Dockerfile
aledraa's picture
Update Dockerfile
dfcc57e verified
# Use an official Python runtime as a parent image
FROM python:3.10-slim
# Set the working directory in the container
WORKDIR /code
# Set environment variables to tell Hugging Face libraries where to cache models.
ENV HF_HOME=/code/cache
ENV HF_HUB_CACHE=/code/cache
# Deprecated but harmless
ENV TRANSFORMERS_CACHE=/code/cache
# --- FIX FOR PERMISSION ERROR v2 ---
# Create the cache directory AND give it open write permissions for all users.
# This ensures that the non-root user running the CMD can write to it.
RUN mkdir -p /code/cache && \
chmod -R 777 /code/cache
# -----------------------------------
# Copy the requirements file into the container at /code
COPY ./requirements.txt /code/requirements.txt
# Install any needed packages specified in requirements.txt
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
# Copy the rest of the application code into the container at /code
COPY ./main.py /code/main.py
# Command to run the app using uvicorn.
# It will be available on port 7860, the standard for HF Spaces
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]