Skip to content

Commit b23a709

Browse files
committed
fix: supress warning
1 parent beb278c commit b23a709

1 file changed

Lines changed: 24 additions & 1 deletion

File tree

packages/extractor/python/extract_server.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,33 @@
66
"""
77
import json
88
import sys
9+
import warnings
10+
import logging
911
from pathlib import Path
1012

13+
# Suppress all warnings and logging from Docling and its dependencies
14+
warnings.filterwarnings("ignore")
15+
logging.disable(logging.CRITICAL) # Disable all logging
16+
17+
import os
18+
import contextlib
19+
1120
from docling.document_converter import DocumentConverter
1221
from docling.datamodel.base_models import InputFormat
1322

1423

24+
@contextlib.contextmanager
25+
def suppress_stderr():
26+
"""Temporarily suppress stderr to hide Docling's verbose output."""
27+
with open(os.devnull, 'w') as devnull:
28+
old_stderr = sys.stderr
29+
sys.stderr = devnull
30+
try:
31+
yield
32+
finally:
33+
sys.stderr = old_stderr
34+
35+
1536
def strip_image_data(extraction: dict) -> dict:
1637
"""Remove base64 image data from extraction to reduce size."""
1738
if "pictures" in extraction:
@@ -64,7 +85,9 @@ def main():
6485
print(json.dumps({"success": False, "error": f"File not found: {file_path}"}), flush=True)
6586
continue
6687

67-
result = extract(converter, file_path)
88+
# Suppress stderr during extraction to hide Docling's verbose output
89+
with suppress_stderr():
90+
result = extract(converter, file_path)
6891
print(json.dumps({"success": True, **result}), flush=True)
6992

7093
except Exception as e:

0 commit comments

Comments
 (0)