Spaces:
Running on Zero
Running on Zero
Upload app.py with huggingface_hub
Browse files68 unmodified lines6970717273747576777879808182838485868788899091929394959697989910010110210310423 unmodified lines12812913013113213313413513613746 unmodified lines18418518618718818919068 unmodified linesevaluator.layout.warm()evaluator.detector.warm()import time as _time # noqa: E402import functools as _ft # noqa: E402def _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 coverprint("timing patch failed", _cls, _name, e)MAX_PDF_PAGES = 5LAYOUT_THRESHOLD = 0.3MAX_NEW_TOKENS = 51223 unmodified linesdef _duration(file_path, mode="page", layout_threshold=LAYOUT_THRESHOLD, max_new_tokens=MAX_NEW_TOKENS):n = 1if file_path and str(file_path).lower().endswith(".pdf"):n = MAX_PDF_PAGESreturn 60 + 50 * n@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. ""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():68 unmodified lines6970717273747523 unmodified lines9910010110210310410510610710810911011111211311446 unmodified lines16116216316416516616768 unmodified linesevaluator.layout.warm()evaluator.detector.warm()MAX_PDF_PAGES = 3LAYOUT_THRESHOLD = 0.3MAX_NEW_TOKENS = 51223 unmodified linesdef _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 = 1if file_path and str(file_path).lower().endswith(".pdf"):try:import pypdfium2n = max(1, min(MAX_PDF_PAGES, len(pypdfium2.PdfDocument(str(file_path)))))except Exception:n = MAX_PDF_PAGESreturn 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 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