Commit Β·
1e5247f
1
Parent(s): ba5ca25
Move @spaces.GPU to picklable stub; run process_pdf on CPU to avoid ZeroGPU pickle crash
Browse files
docling_pdf_processor/web/gradio_app.py
CHANGED
|
@@ -79,6 +79,23 @@ DEFAULT_GROQ = settings.groq_api_key or ""
|
|
| 79 |
|
| 80 |
# ββ Helpers ββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 81 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
def _cleanup_rag(session_id: str | None) -> None:
|
| 83 |
if session_id and session_id in RAG_SYSTEMS:
|
| 84 |
del RAG_SYSTEMS[session_id]
|
|
@@ -107,7 +124,6 @@ def _format_status(status: str) -> str:
|
|
| 107 |
|
| 108 |
# ββ Event handlers βββββββββββββββββββββββββββββββββββββββββββββ
|
| 109 |
|
| 110 |
-
@spaces.GPU
|
| 111 |
def process_pdf(
|
| 112 |
pdf_file,
|
| 113 |
openrouter_key: str,
|
|
|
|
| 79 |
|
| 80 |
# ββ Helpers ββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 81 |
|
| 82 |
+
@spaces.GPU
|
| 83 |
+
def _zero_gpu_stub() -> bool:
|
| 84 |
+
"""ZeroGPU Spaces require at least one ``@spaces.GPU`` function to be
|
| 85 |
+
detected at startup, otherwise the Space fails with
|
| 86 |
+
'No @spaces.GPU function detected during startup'.
|
| 87 |
+
|
| 88 |
+
The real pipeline (``process_pdf``) is a generator that streams progress
|
| 89 |
+
from a background thread and keeps a live ``PipelineOrchestrator`` (which
|
| 90 |
+
holds a ``_thread.lock``) in gradio state. None of that is picklable, and
|
| 91 |
+
ZeroGPU runs decorated functions in an isolated process returning results
|
| 92 |
+
via a pickle queue (``cannot pickle '_thread.lock' object``). So the
|
| 93 |
+
pipeline runs on CPU in-process and this trivial picklable stub exists
|
| 94 |
+
solely to satisfy the ZeroGPU startup check.
|
| 95 |
+
"""
|
| 96 |
+
return True
|
| 97 |
+
|
| 98 |
+
|
| 99 |
def _cleanup_rag(session_id: str | None) -> None:
|
| 100 |
if session_id and session_id in RAG_SYSTEMS:
|
| 101 |
del RAG_SYSTEMS[session_id]
|
|
|
|
| 124 |
|
| 125 |
# ββ Event handlers βββββββββββββββββββββββββββββββββββββββββββββ
|
| 126 |
|
|
|
|
| 127 |
def process_pdf(
|
| 128 |
pdf_file,
|
| 129 |
openrouter_key: str,
|