mindspark121's picture
Update Dockerfile
2b5b95f verified
# Use an official Python runtime as a parent image
FROM python:3.9-slim
# Set the working directory
WORKDIR /app
# Create a writable cache directory
RUN mkdir -p /app/cache
# Set environment variables for Hugging Face cache
ENV HF_HOME="/app/cache"
ENV TRANSFORMERS_CACHE="/app/cache"
ENV SENTENCE_TRANSFORMERS_HOME="/app/cache"
# Copy requirements.txt and install dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# Force model download during build (ensures model is available inside container)
RUN python -c "from sentence_transformers import SentenceTransformer; SentenceTransformer('sentence-transformers/all-MiniLM-L6-v2', cache_folder='/app/cache')"
RUN python -c "from transformers import AutoModelForSeq2SeqLM; AutoModelForSeq2SeqLM.from_pretrained('google/long-t5-tglobal-base', cache_dir='/app/cache')"
# Copy the entire app into the container
COPY . .
# Expose the port FastAPI will run on
EXPOSE 7860
# Run the FastAPI app with Uvicorn
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]