xxyyy123 commited on
Commit
807de1e
·
verified ·
1 Parent(s): 9c02471

Recover PDF batches from slow or interrupted streams

Browse files
README.md CHANGED
@@ -27,7 +27,9 @@ visual-region crops. Model tokens stream into the interface as they are generate
27
  PDFs are rasterized locally and processed one page at a time in Base mode. Up to
28
  four pages share one streamed GPU request by default, while each page is still
29
  inferred independently and sequentially. The browser merges the results, so long
30
- documents do not have to fit inside one ZeroGPU lease. This demo
 
 
31
  intentionally does not expose a separate Long mode.
32
 
33
  The five packaged examples cover two financial tables, two Chinese handwriting
 
27
  PDFs are rasterized locally and processed one page at a time in Base mode. Up to
28
  four pages share one streamed GPU request by default, while each page is still
29
  inferred independently and sequentially. The browser merges the results, so long
30
+ documents do not have to fit inside one ZeroGPU lease. If a Gradio stream closes
31
+ without an explicit backend error, the browser resumes once from the first
32
+ unfinished page while retaining every completed page. This demo
33
  intentionally does not expose a separate Long mode.
34
 
35
  The five packaged examples cover two financial tables, two Chinese handwriting
app.py CHANGED
@@ -372,7 +372,6 @@ def infer_stream(page_image: Image.Image) -> Iterator[str]:
372
  skip_prompt=True,
373
  skip_special_tokens=True,
374
  clean_up_tokenization_spaces=False,
375
- timeout=30.0,
376
  )
377
  errors: list[BaseException] = []
378
 
@@ -503,6 +502,10 @@ def run_ocr(
503
  batch_start_page = page_index + 1
504
  batch_end_page = batch_end_index
505
  completed_pages: list[dict[str, Any]] = []
 
 
 
 
506
 
507
  for current_index in range(page_index, batch_end_index):
508
  page_number = current_index + 1
@@ -559,6 +562,11 @@ def run_ocr(
559
  "elapsed_seconds": round(time.perf_counter() - page_started, 3),
560
  }
561
  completed_pages.append(completed_page)
 
 
 
 
 
562
  yield stream_payload(
563
  event="page_complete",
564
  pages=[completed_page],
@@ -570,6 +578,10 @@ def run_ocr(
570
  batch_end_page=batch_end_page,
571
  )
572
 
 
 
 
 
573
  yield stream_payload(
574
  event="complete",
575
  pages=completed_pages,
 
372
  skip_prompt=True,
373
  skip_special_tokens=True,
374
  clean_up_tokenization_spaces=False,
 
375
  )
376
  errors: list[BaseException] = []
377
 
 
502
  batch_start_page = page_index + 1
503
  batch_end_page = batch_end_index
504
  completed_pages: list[dict[str, Any]] = []
505
+ print(
506
+ f"[ocr] batch start pages {batch_start_page}-{batch_end_page}/{total_pages}",
507
+ flush=True,
508
+ )
509
 
510
  for current_index in range(page_index, batch_end_index):
511
  page_number = current_index + 1
 
562
  "elapsed_seconds": round(time.perf_counter() - page_started, 3),
563
  }
564
  completed_pages.append(completed_page)
565
+ print(
566
+ f"[ocr] page {page_number}/{total_pages} complete "
567
+ f"({len(markdown)} chars, {completed_page['elapsed_seconds']}s)",
568
+ flush=True,
569
+ )
570
  yield stream_payload(
571
  event="page_complete",
572
  pages=[completed_page],
 
578
  batch_end_page=batch_end_page,
579
  )
580
 
581
+ print(
582
+ f"[ocr] batch complete pages {batch_start_page}-{batch_end_page}/{total_pages}",
583
+ flush=True,
584
+ )
585
  yield stream_payload(
586
  event="complete",
587
  pages=completed_pages,
dist/assets/{index-GMDMVVb1.js → index-C_zhAi_h.js} RENAMED
The diff for this file is too large to render. See raw diff
 
dist/index.html CHANGED
@@ -22,7 +22,7 @@
22
  };
23
  </script>
24
  <script defer src="./vendor/mathjax/tex-chtml-full.js"></script>
25
- <script type="module" crossorigin src="./assets/index-GMDMVVb1.js"></script>
26
  <link rel="stylesheet" crossorigin href="./assets/index-CQtDzYS-.css">
27
  </head>
28
  <body>
 
22
  };
23
  </script>
24
  <script defer src="./vendor/mathjax/tex-chtml-full.js"></script>
25
+ <script type="module" crossorigin src="./assets/index-C_zhAi_h.js"></script>
26
  <link rel="stylesheet" crossorigin href="./assets/index-CQtDzYS-.css">
27
  </head>
28
  <body>