# DiagraMine — Streamlit demo + FastAPI image for the Hugging Face Space. # # Same as the repo's Dockerfile, plus what a Space needs: Hugging Face runs # the container as user 1000, so the app lives in that user's home (PaddleOCR # caches its models under ~/.paddleocr); torch comes from the CPU-only index # (the default wheels pull in CUDA, several GB); and the OCR models are fetched # at build time so the first /extract after a cold start doesn't download them. # nginx puts both apps on the one public port: the demo at /, the API at # /extract, /health and /docs (see nginx.conf and start.sh). FROM python:3.11-slim ENV PYTHONUNBUFFERED=1 \ PYTHONDONTWRITEBYTECODE=1 \ PIP_NO_CACHE_DIR=1 \ DEBIAN_FRONTEND=noninteractive # OS libs: OpenCV needs libGL + libglib; matplotlib needs libfreetype/libpng; # paddlepaddle's CPU build links the OpenMP runtime (libgomp). RUN apt-get update && apt-get install -y --no-install-recommends \ libgomp1 \ libgl1 \ libglib2.0-0 \ libsm6 \ libxext6 \ libxrender1 \ libfreetype6 \ libpng16-16 \ nginx \ && rm -rf /var/lib/apt/lists/* RUN useradd -m -u 1000 user USER user ENV HOME=/home/user \ PATH=/home/user/.local/bin:$PATH \ MPLCONFIGDIR=/home/user/.config/matplotlib WORKDIR /home/user/app # Install Python deps first for cacheability. COPY --chown=user requirements.txt ./ RUN pip install --user --upgrade pip \ && pip install --user --extra-index-url https://download.pytorch.org/whl/cpu -r requirements.txt # Source. COPY --chown=user src/ ./src/ COPY --chown=user diagram_analysis.py ./ COPY --chown=user data/icon_templates/ ./data/icon_templates/ COPY --chown=user app.py ui_theme.py search_interview_test.png ./ COPY --chown=user .streamlit/ ./.streamlit/ COPY --chown=user data/eval/ ./data/eval/ COPY --chown=user nginx.conf start.sh ./ # PaddleOCR's English det/rec/cls models (~15 MB), fetched now rather than on # the first request. torch first, as in src/text_detection/paddle_detector.py. RUN python -c "import torch; from paddleocr import PaddleOCR; PaddleOCR(use_angle_cls=True, lang='en', show_log=False)" EXPOSE 8000 CMD ["bash", "start.sh"]