validops-east-3 commited on
Commit
6ac032f
·
verified ·
1 Parent(s): 9cacfae

Deploy 0cf602f4c2fecaf8c206bad7e3f4cc7b7642e444

Browse files
Files changed (2) hide show
  1. Dockerfile +90 -54
  2. README.md +4 -5
Dockerfile CHANGED
@@ -1,59 +1,95 @@
1
- # docqa — Document Data Extraction API
2
- #
3
- # Loads impira/layoutlm-invoices straight from the Hugging Face cache, so
4
- # there is no model artifact to host in this repository.
5
- #
6
- # Serves on 7860, the port this Space previously used for llama-server, so no
7
- # Space port setting changes are needed.
8
-
9
- FROM python:3.11-slim-bookworm
10
-
11
- # poppler-utils -> pdftotext/pdftoppm for the PDF text layer and rasterising
12
- # scans; tesseract-ocr -> OCR for images and scanned pages.
13
- RUN apt-get update && apt-get install -y --no-install-recommends \
14
- poppler-utils \
15
- tesseract-ocr \
16
- tesseract-ocr-eng \
17
- curl \
18
- libgomp1 \
19
- && rm -rf /var/lib/apt/lists/*
20
-
21
- WORKDIR /app
22
-
23
- COPY requirements.txt ./
24
- RUN pip install --no-cache-dir -r requirements.txt
25
-
26
- COPY docqa ./docqa
27
- ENV PYTHONPATH=/app/docqa
28
-
29
- # The model is pulled from the Hub at first start and cached under
30
- # /root/.cache/huggingface. Pre-fetching during build means a cold Space does
31
- # not serve requests until the weights are on disk.
32
- ARG MODEL_ID=impira/layoutlm-invoices
33
- RUN python -c "\
34
- from huggingface_hub import snapshot_download; \
35
- print(snapshot_download('${MODEL_ID}', \
36
- allow_patterns=['*.json','*.txt','*.bin','*.safetensors','*.model'])); \
37
- " || echo 'prefetch failed; model will download at first start'
38
-
39
- ENV DOCX_MODEL_ID=impira/layoutlm-invoices \
40
- DOCX_DEVICE=cpu \
41
- DOCX_TORCH_THREADS=4 \
42
- DOCX_BATCH_SIZE=8 \
43
- DOCX_MAX_PAGES=3 \
44
- DOCX_MAX_UPLOAD_MB=25 \
45
- DOCX_CONFIDENCE_THRESHOLD=0.5 \
46
- DOCX_REQUEST_TIMEOUT_S=60 \
47
- DOCX_LOG_JSON=false \
48
- HF_HOME=/app/.cache/huggingface \
49
- PORT=7860
50
 
51
  EXPOSE 7860
52
 
53
- # Warm the model first, then serve. The model loads before uvicorn binds, so a
54
- # passing health check means inference will actually work rather than the
55
- # process merely being alive.
56
- HEALTHCHECK --interval=30s --timeout=10s --start-period=600s --retries=6 \
57
  CMD curl -fsS http://127.0.0.1:7860/health || exit 1
58
 
59
- CMD ["sh", "-c", "python -c \"from docxextract.engine import get_engine; from docxextract.config import get_settings; s=get_settings(); get_engine(s).warmup(); print('model warm')\" && exec uvicorn docxextract.api:app --host 0.0.0.0 --port ${PORT} --workers 1 --timeout-keep-alive 65"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # ============================================================================
2
+ # ACTIVE: llama-server (Qwen3-0.6B Q8_0), OpenAI-compatible, port 7860
3
+ # ============================================================================
4
+
5
+ FROM ghcr.io/ggml-org/llama.cpp:server
6
+
7
+ # pre-build: bake the official Q8_0 GGUF into the image (610 MB)
8
+ RUN mkdir -p /models && \
9
+ curl -fL --retry 3 -o /models/Qwen3-0.6B-Q8_0.gguf \
10
+ "https://huggingface.co/Qwen/Qwen3-0.6B-GGUF/resolve/main/Qwen3-0.6B-Q8_0.gguf" && \
11
+ ls -lh /models
12
+
13
+ # key lives in .env (llama-server reads the LLAMA_API_KEY env var natively)
14
+ COPY .env /app/.env
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
 
16
  EXPOSE 7860
17
 
18
+ HEALTHCHECK --interval=30s --timeout=5s --start-period=120s --retries=6 \
 
 
 
19
  CMD curl -fsS http://127.0.0.1:7860/health || exit 1
20
 
21
+ # source .env unless the key is already set (Space secret / --env-file win)
22
+ ENTRYPOINT ["/bin/sh", "-c", "if [ -z \"$LLAMA_API_KEY\" ]; then set -a; . /app/.env; set +a; fi; exec /app/llama-server \"$@\"", "--"]
23
+
24
+ # -c is TOTAL across slots, so 32768 / 2 slots = 16384 ctx per request.
25
+ # Raise -c to 65536 if you want a full 32k per concurrent request.
26
+ CMD ["-m", "/models/Qwen3-0.6B-Q8_0.gguf", \
27
+ "--host", "0.0.0.0", \
28
+ "--port", "7860", \
29
+ "-c", "32768", \
30
+ "-np", "2", \
31
+ "-t", "2", \
32
+ "-tb", "4", \
33
+ "-ctk", "q8_0", \
34
+ "-ctv", "q8_0", \
35
+ "--jinja", \
36
+ "--alias", "Qwen3-0.6B"]
37
+
38
+ # ============================================================================
39
+ # COMMENTED OUT: docqa — Document Data Extraction API (Python + FastAPI)
40
+ #
41
+ # Kept for later, not built. To restore it, delete the FROM/ENTRYPOINT/CMD above
42
+ # and uncomment the block below. Its own README is in docqa/.
43
+ # ============================================================================
44
+ #
45
+ # FROM python:3.11-slim-bookworm
46
+ #
47
+ # # poppler-utils -> pdftotext/pdftoppm for the PDF text layer and rasterising
48
+ # # scans; tesseract-ocr -> OCR for images and scanned pages.
49
+ # RUN apt-get update && apt-get install -y --no-install-recommends \
50
+ # poppler-utils \
51
+ # tesseract-ocr \
52
+ # tesseract-ocr-eng \
53
+ # curl \
54
+ # libgomp1 \
55
+ # && rm -rf /var/lib/apt/lists/*
56
+ #
57
+ # WORKDIR /app
58
+ #
59
+ # COPY requirements.txt ./
60
+ # RUN pip install --no-cache-dir -r requirements.txt
61
+ #
62
+ # COPY docqa ./docqa
63
+ # ENV PYTHONPATH=/app/docqa
64
+ #
65
+ # # The model is pulled from the Hub at first start and cached under
66
+ # # /root/.cache/huggingface. Pre-fetching during build means a cold Space does
67
+ # # not serve requests until the weights are on disk.
68
+ # ARG MODEL_ID=impira/layoutlm-invoices
69
+ # RUN python -c "\
70
+ # from huggingface_hub import snapshot_download; \
71
+ # print(snapshot_download('${MODEL_ID}', \
72
+ # allow_patterns=['*.json','*.txt','*.bin','*.safetensors','*.model'])); \
73
+ # " || echo 'prefetch failed; model will download at first start'
74
+ #
75
+ # ENV DOCX_MODEL_ID=impira/layoutlm-invoices \
76
+ # DOCX_DEVICE=cpu \
77
+ # DOCX_TORCH_THREADS=4 \
78
+ # DOCX_BATCH_SIZE=8 \
79
+ # DOCX_MAX_PAGES=3 \
80
+ # DOCX_MAX_UPLOAD_MB=25 \
81
+ # DOCX_CONFIDENCE_THRESHOLD=0.5 \
82
+ # DOCX_REQUEST_TIMEOUT_S=60 \
83
+ # DOCX_LOG_JSON=false \
84
+ # HF_HOME=/app/.cache/huggingface \
85
+ # PORT=7860
86
+ #
87
+ # EXPOSE 7860
88
+ #
89
+ # # Warm the model first, then serve. The model loads before uvicorn binds, so a
90
+ # # passing health check means inference will actually work rather than the
91
+ # # process merely being alive.
92
+ # HEALTHCHECK --interval=30s --timeout=10s --start-period=600s --retries=6 \
93
+ # CMD curl -fsS http://127.0.0.1:7860/health || exit 1
94
+ #
95
+ # CMD ["sh", "-c", "python -c \"from docxextract.engine import get_engine; from docxextract.config import get_settings; s=get_settings(); get_engine(s).warmup(); print('model warm')\" && exec uvicorn docxextract.api:app --host 0.0.0.0 --port ${PORT} --workers 1 --timeout-keep-alive 65"]
README.md CHANGED
@@ -1,10 +1,9 @@
1
  ---
2
- title: Document Data Extraction
3
- emoji: 🧾
4
- colorFrom: blue
5
- colorTo: indigo
6
  sdk: docker
7
  pinned: false
8
  app_port: 7860
9
- license: mit
10
  ---
 
1
  ---
2
+ title: OpenAI Chat
3
+ emoji: 🤖
4
+ colorFrom: purple
5
+ colorTo: green
6
  sdk: docker
7
  pinned: false
8
  app_port: 7860
 
9
  ---