FROM python:3.11-slim # System deps RUN apt-get update && apt-get install -y --no-install-recommends \ build-essential libxml2-dev libxslt1-dev \ && rm -rf /var/lib/apt/lists/* # Create non-root user (HF Spaces requirement) RUN useradd -m -u 1000 appuser WORKDIR /app # Install PyTorch with CUDA 12.1 support RUN pip install --no-cache-dir \ torch==2.3.1 --index-url https://download.pytorch.org/whl/cu121 # Install ML dependencies RUN pip install --no-cache-dir \ transformers>=4.44.0 \ accelerate>=0.34.0 \ "bitsandbytes>=0.46.1" \ sentencepiece>=0.2.0 \ huggingface_hub>=0.25.0 # Install backend dependencies COPY murshid_backend/requirements_light.txt ./requirements.txt RUN pip install --no-cache-dir -r requirements.txt \ && pip install --no-cache-dir openpyxl aiofiles scikit-learn # Copy backend code COPY murshid_backend/ ./murshid_backend/ # Copy model files COPY Needed/ ./Needed/ # Copy frontend COPY murshid_frontend/ ./murshid_frontend/ # Create writable directory for SQLite DB + HF cache RUN mkdir -p /app/data /home/appuser/.cache && chown -R appuser:appuser /app /home/appuser # Setup environment ENV MURSHID_DB_URL=sqlite:////app/data/murshid.db ENV MURSHID_MODELS_DIR=/app/Needed ENV MURSHID_SKIP_LLM=false ENV SECRET_KEY=murshid_hf_space_2026 ENV PORT=7860 ENV HF_HOME=/home/appuser/.cache/huggingface ENV TRANSFORMERS_CACHE=/home/appuser/.cache/huggingface/hub # Run DB migrations + import templates + start server COPY start.sh ./start.sh RUN chmod +x start.sh USER appuser EXPOSE 7860 CMD ["./start.sh"]