Spaces:
Running
Running
File size: 1,839 Bytes
12089c6 e13d740 12089c6 dd0d525 b398b47 dd0d525 b398b47 dd0d525 b398b47 12089c6 cf104cb e13d740 cf104cb e13d740 cf104cb 94bf399 12089c6 dd0d525 94bf399 c31d9d3 12089c6 94bf399 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | FROM python:3.10-slim
WORKDIR /app
# Install system dependencies including FFmpeg
RUN apt-get update && apt-get install -y --no-install-recommends \
ffmpeg \
build-essential \
git \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Create a non-root user to run the application
RUN useradd -m appuser
# Set environment variables for controlling cache locations
ENV TRANSFORMERS_CACHE=/tmp/.cache/huggingface/transformers
ENV HF_HOME=/tmp/.cache/huggingface
ENV HF_DATASETS_CACHE=/tmp/.cache/huggingface/datasets
ENV SENTENCE_TRANSFORMERS_HOME=/tmp/.cache/torch/sentence_transformers
ENV TORCH_HOME=/tmp/.cache/torch
# Create cache directories with proper permissions
RUN mkdir -p /tmp/.cache/huggingface/transformers && \
mkdir -p /tmp/.cache/huggingface/datasets && \
mkdir -p /tmp/.cache/torch/sentence_transformers && \
mkdir -p /tmp/.cache/torch/hub && \
chmod -R 777 /tmp/.cache
# Copy requirements first for better caching
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# Install TensorFlow (CPU version to save space)
RUN pip install --no-cache-dir tensorflow-cpu==2.12.0
# Install additional dependencies directly
RUN pip install --no-cache-dir sentence-transformers>=2.2.2
# Download sentence-transformers model
RUN python -c "from sentence_transformers import SentenceTransformer; SentenceTransformer('all-MiniLM-L6-v2')"
# Run NLTK downloads
RUN python -m nltk.downloader punkt wordnet
# Copy the rest of the application
COPY . .
# Make sure the non-root user can access the application files
RUN chown -R appuser:appuser /app
RUN chmod -R 755 /app
# Switch to non-root user
USER appuser
# Expose the port Hugging Face Spaces expects (7860)
EXPOSE 7860
# Run using uvicorn
CMD ["uvicorn", "fastapi_app:app", "--host", "0.0.0.0", "--port", "7860"] |