Spaces:
Running
Running
FROM python:3.8 | |
# Set a writable cache directory for Hugging Face models | |
ENV HF_HOME="/tmp/huggingface_cache" | |
ENV MPLCONFIGDIR="/tmp/matplotlib_cache" | |
ENV TRANSFORMERS_CACHE="/tmp/huggingface" | |
ENV NUMBA_CACHE_DIR="/tmp/numba_cache" | |
# Create and set correct permissions for cache directories | |
RUN mkdir -p $HF_HOME $MPLCONFIGDIR $TRANSFORMERS_CACHE $NUMBA_CACHE_DIR \ | |
&& chmod -R 777 $HF_HOME $MPLCONFIGDIR $TRANSFORMERS_CACHE $NUMBA_CACHE_DIR | |
# Install system dependencies | |
RUN apt-get update && apt-get install -y \ | |
ffmpeg \ | |
&& rm -rf /var/lib/apt/lists/* | |
# Set up a non-root user to avoid permission issues | |
RUN useradd -m appuser | |
USER appuser | |
# Set the PATH to include local bin directory | |
ENV PATH="/home/appuser/.local/bin:$PATH" | |
# Install Python dependencies | |
COPY --chown=appuser:appuser requirements.txt . | |
RUN pip install --no-cache-dir -r requirements.txt | |
# Manually install uvicorn in case it failed above | |
RUN pip install uvicorn | |
# Verify that uvicorn was installed | |
RUN pip show uvicorn | |
# Copy the API code | |
COPY --chown=appuser:appuser . . | |
# Expose the port | |
EXPOSE 5000 | |
# Run the application | |
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "5000"] | |