hackrx / Dockerfile
Manjesh501's picture
Fix
5505d86
FROM python:3.9-slim
WORKDIR /code
# Set environment variables for Hugging Face cache (use /code directory)
ENV HF_HOME=/code/.cache/huggingface
ENV TRANSFORMERS_CACHE=/code/.cache/huggingface
ENV HF_HUB_CACHE=/code/.cache/huggingface
ENV HF_DATASETS_CACHE=/code/.cache/huggingface
# Create cache directories with proper permissions
RUN mkdir -p /code/.cache/huggingface && \
chmod -R 777 /code/.cache && \
chown -R nobody:nogroup /code/.cache
# Install system dependencies
RUN apt-get update && apt-get install -y \
build-essential \
python3-dev \
curl \
&& rm -rf /var/lib/apt/lists/*
# Install Python dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir --upgrade pip setuptools wheel
RUN pip install --no-cache-dir -r requirements.txt
# Copy application code
COPY . .
# Ensure cache directories exist and have proper permissions
RUN mkdir -p /code/.cache/huggingface && \
chmod -R 777 /code/.cache && \
chown -R nobody:nogroup /code/.cache
# Pre-download the sentence-transformers model during build
RUN python download_model.py || echo "Warning: Model download failed, will retry at runtime"
# Create a startup script for Hugging Face Spaces
RUN echo '#!/bin/bash\n\
echo "Starting HackRx 6.0 on Hugging Face Spaces..."\n\
echo "Cache directory: $HF_HOME"\n\
echo "Using app.py as entry point..."\n\
echo "Starting uvicorn server on port 7860..."\n\
echo "App will be available at: https://huggingface.co/spaces/Manjesh501/hackrx"\n\
exec uvicorn app:app --host 0.0.0.0 --port 7860 --workers 1 --log-level info\n\
' > /code/start.sh && chmod +x /code/start.sh
# Hugging Face Spaces uses port 7860
EXPOSE 7860
# Set environment variables
ENV HOST=0.0.0.0
ENV PORT=7860
# Command to run the application
CMD ["/code/start.sh"]