Spaces:
Sleeping
Sleeping
File size: 2,973 Bytes
fa1fead 4ef5ca6 fa1fead 4ef5ca6 fa1fead 4ef5ca6 fa1fead 4ef5ca6 fa1fead 4ef5ca6 fa1fead 4ef5ca6 fa1fead 4ef5ca6 fa1fead 4ef5ca6 fa1fead 4ef5ca6 fa1fead 4ef5ca6 fa1fead 4ef5ca6 fa1fead 4ef5ca6 fa1fead | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | # ββ SmartDocs API β Hugging Face Spaces Docker ββββββββββββββββββββββββββββββββ
# ββ Stage 1: dependency builder βββββββββββββββββββββββββββββββββββββββββββββββ
FROM python:3.13-slim-bookworm AS builder
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
git \
curl \
libgomp1 \
libglib2.0-0 \
libsm6 \
libxext6 \
&& rm -rf /var/lib/apt/lists/*
# Install uv (fast package manager)
COPY --from=ghcr.io/astral-sh/uv:0.5.17 /uv /uvx /usr/local/bin/
# IMPORTANT: build venv in /app (final path to avoid break)
WORKDIR /app
RUN uv venv .venv && \
uv pip install --python .venv/bin/python \
fastapi "uvicorn[standard]" python-multipart \
langchain-core langgraph langsmith openai \
langchain-openai langchain-huggingface \
sentence-transformers rank-bm25 scikit-learn \
langdetect pdfplumber asyncpg pgvector \
flashrank redis pydantic "pydantic-settings" \
python-dotenv pyyaml aiohttp tavily-python \
indic-nlp-library presidio-analyzer presidio-anonymizer \
"opentelemetry-sdk" tenacity httpx numpy
# Clone Indic NLP resources
RUN git clone --depth 1 \
https://github.com/anoopkunchukuttan/indic_nlp_resources.git \
/app/indic_nlp_resources
# ββ Stage 2: runtime image ββββββββββββββββββββββββββββββββββββββββββββββββββββ
FROM python:3.13-slim-bookworm
RUN apt-get update && apt-get install -y --no-install-recommends \
libgomp1 \
libglib2.0-0 \
&& rm -rf /var/lib/apt/lists/*
# HF Spaces requires non-root user
RUN useradd -m -u 1000 -s /bin/bash appuser
WORKDIR /app
# Copy prebuilt environment and resources
COPY --from=builder /app/.venv /app/.venv
COPY --from=builder /app/indic_nlp_resources /app/indic_nlp_resources
# Copy app code
COPY --chown=appuser:appuser . .
# Environment setup
ENV PATH="/app/.venv/bin:$PATH" \
PYTHONPATH="/app" \
PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
INDIC_RESOURCES_PATH="/app/indic_nlp_resources" \
EMBEDDING_DEVICE="cpu" \
EMBEDDING_BATCH_SIZE="8" \
ENVIRONMENT="production" \
SENTENCE_TRANSFORMERS_HOME="/app/.cache/st" \
HF_HOME="/app/.cache/hf" \
PORT=7860
# Create cache dirs
RUN mkdir -p /app/.cache/st /app/.cache/hf && \
chown -R appuser:appuser /app
USER appuser
# HF Spaces port
EXPOSE 7860
# Healthcheck
HEALTHCHECK --interval=30s --timeout=15s --start-period=120s --retries=5 \
CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:7860/health/ping')" || exit 1
# Start server
CMD ["uvicorn", "api.main:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "1", "--log-level", "info"] |