Spaces:
Running on Zero
Running on Zero
Upload app.py with huggingface_hub
Browse files68 unmodified lines697071727374757677787980818283848586878889909192939495969798991001017273747523 unmodified lines9910010110210310410510610710810913313411011111211311446 unmodified lines16116216318716416516616768 unmodified linesevaluator.layout.warm()evaluator.detector.warm()
import time as _time # noqa: E402import functools as _ft # noqa: E402
def _timed(cls, name): fn = getattr(cls, name)
@_ft.wraps(fn) def wrapper(*a, **k): t = _time.time() try: return fn(*a, **k) finally: print(f"[timing] {cls.__name__}.{name}: {_time.time() - t:.2f}s", flush=True)
setattr(cls, name, wrapper)
for _cls, _name in [ (type(evaluator.layout), "predict"), (type(evaluator.detector), "predict"), (type(evaluator), "recognize_pieces"), (type(evaluator), "evaluate"),]: try: _timed(_cls, _name) except Exception as e: # pragma: no cover print("timing patch failed", _cls, _name, e)
MAX_PDF_PAGES = 5MAX_PDF_PAGES = 3LAYOUT_THRESHOLD = 0.3MAX_NEW_TOKENS = 512
23 unmodified lines
def _duration(file_path, mode="page", layout_threshold=LAYOUT_THRESHOLD, max_new_tokens=MAX_NEW_TOKENS): # Measured on ZeroGPU: ~15-35 s per page warm, plus ~30 s one-off warmup on a cold worker. n = 1 if file_path and str(file_path).lower().endswith(".pdf"): try: import pypdfium2
n = max(1, min(MAX_PDF_PAGES, len(pypdfium2.PdfDocument(str(file_path))))) except Exception: n = MAX_PDF_PAGES return 60 + 50 * n n = MAX_PDF_PAGES return 90 + 45 * (n - 1)
@spaces.GPU(duration=_duration)46 unmodified lines "# D-OCR Preview — Bangla document OCR\n" "Modular OCR pipeline for printed and handwritten **Bangla** documents: PP-DocLayout-S layout detection, " "PP-OCRv5 text detection, Table Transformer table structure and a SigLIP2 + Qwen3.5-0.8B text recognizer. " "Upload an image or a PDF (first 5 pages) and get the text, a detection overlay and HTML reconstructions. " "Upload an image or a PDF (first 3 pages) and get the text, a detection overlay and HTML reconstructions. " "Model: [D-OCR/D-OCR-preview](https://huggingface.co/D-OCR/D-OCR-preview) · License: CC BY-NC 4.0 (non-commercial)." ) with gr.Row():app.py+10-33