Shubham170793's picture
Update Dockerfile
32a3bbb verified
# ============================================================
# 🧩 Enterprise Knowledge Assistant — Hugging Face Space Dockerfile
# ============================================================
# ✅ Use Python 3.10 — stable for FAISS, PyMuPDF, Transformers
FROM python:3.10-slim
# ------------------------------------------------------------
# 1️⃣ Set working directory
# ------------------------------------------------------------
WORKDIR /app
# ------------------------------------------------------------
# 2️⃣ Environment variables
# ------------------------------------------------------------
# - PYTHONUNBUFFERED: ensures logs show up live
# - HF_*: route all Hugging Face model cache to writable folder (/app/hf_cache)
# - STREAMLIT server flags: make Streamlit work inside HF Space
ENV PYTHONUNBUFFERED=1 \
HF_HOME=/app/hf_cache \
TRANSFORMERS_CACHE=/app/hf_cache \
HF_DATASETS_CACHE=/app/hf_cache \
HF_MODULES_CACHE=/app/hf_cache
# ------------------------------------------------------------
# 3️⃣ Install system dependencies
# ------------------------------------------------------------
RUN apt-get update && apt-get install -y \
build-essential \
git \
&& rm -rf /var/lib/apt/lists/*
# ------------------------------------------------------------
# 4️⃣ Copy requirements first for Docker layer caching
# ------------------------------------------------------------
COPY requirements.txt .
# ------------------------------------------------------------
# 5️⃣ Install Python dependencies
# ------------------------------------------------------------
RUN pip install --no-cache-dir -r requirements.txt
# ------------------------------------------------------------
# 6️⃣ Copy the entire app
# ------------------------------------------------------------
COPY . .
# ------------------------------------------------------------
# 7️⃣ Create cache folder with proper permissions
# ------------------------------------------------------------
RUN mkdir -p /app/hf_cache && chmod -R 777 /app/hf_cache
# ------------------------------------------------------------
# 8️⃣ Expose Streamlit’s default port
# ------------------------------------------------------------
EXPOSE 8501
# ------------------------------------------------------------
# 9️⃣ Start Streamlit with flags to fix upload (403) and XSRF issues
# ------------------------------------------------------------
CMD ["streamlit", "run", "src/streamlit_app.py", \
"--server.port=8501", \
"--server.address=0.0.0.0", \
"--server.enableXsrfProtection=false", \
"--server.enableCORS=true"]