Push Bot commited on
Commit
ceadda8
·
1 Parent(s): 2b9d4ff

Preview: auto-choose base64 embed for small PDFs and file iframe for large; apply to pipeline + all debug previews

Browse files
Files changed (1) hide show
  1. app.py +17 -4
app.py CHANGED
@@ -513,6 +513,19 @@ def _pdf_to_iframe_file(pdf_path: Path, width="100%", height="900px") -> str:
513
  except Exception:
514
  return ""
515
 
 
 
 
 
 
 
 
 
 
 
 
 
 
516
  def preview_image_from_pdf(pdf_file):
517
  """Render first page of PDF to PNG for image preview. Returns path or None."""
518
  try:
@@ -773,7 +786,7 @@ def debug_compile_output_zip():
773
 
774
  try:
775
  # Use served file path to avoid data: URI issues
776
- html = _pdf_to_iframe_file(pdf_path, height="700px")
777
  _write_logs(LOG_PATH, logs)
778
  return html
779
  except Exception as e:
@@ -887,7 +900,7 @@ def debug_compile_last_pipeline_zip():
887
  + "</pre>"
888
  )
889
  try:
890
- html = _pdf_to_iframe_file(pdf_path, height="700px")
891
  _write_logs(LOG_PATH, logs)
892
  return html
893
  except Exception as e:
@@ -990,7 +1003,7 @@ def debug_compile_uploaded_zip(zip_file):
990
  + "</pre>"
991
  )
992
  try:
993
- html = _pdf_to_iframe_file(pdf_path, height="700px")
994
  _write_logs(LOG_PATH, logs)
995
  return html
996
  except Exception as e:
@@ -1200,7 +1213,7 @@ def run_pipeline(arxiv_url, pdf_file, openai_key, logo_files, meeting_logo_file,
1200
  try:
1201
  pdf_path = _compile_poster_pdf(OUTPUT_DIR, logs)
1202
  if pdf_path and pdf_path.exists():
1203
- pdf_html = _pdf_to_iframe_file(pdf_path)
1204
  compiled_pdf_file = str(pdf_path)
1205
  logs.append("🖨️ PDF ready for preview in UI.")
1206
  except Exception as e:
 
513
  except Exception:
514
  return ""
515
 
516
+ def _pdf_preview_html(pdf_path: Path, width="100%", height="900px") -> str:
517
+ """Choose base64 embed for small PDFs; served-file iframe for large PDFs.
518
+ This avoids blank previews for large files while keeping inline render for small ones.
519
+ """
520
+ try:
521
+ size = pdf_path.stat().st_size if isinstance(pdf_path, Path) else 0
522
+ except Exception:
523
+ size = 0
524
+ # 5 MB threshold (tunable)
525
+ if size and size <= 5 * 1024 * 1024:
526
+ return _pdf_to_iframe_html(pdf_path, width=width, height=height)
527
+ return _pdf_to_iframe_file(pdf_path, width=width, height=height)
528
+
529
  def preview_image_from_pdf(pdf_file):
530
  """Render first page of PDF to PNG for image preview. Returns path or None."""
531
  try:
 
786
 
787
  try:
788
  # Use served file path to avoid data: URI issues
789
+ html = _pdf_preview_html(pdf_path, height="700px")
790
  _write_logs(LOG_PATH, logs)
791
  return html
792
  except Exception as e:
 
900
  + "</pre>"
901
  )
902
  try:
903
+ html = _pdf_preview_html(pdf_path, height="700px")
904
  _write_logs(LOG_PATH, logs)
905
  return html
906
  except Exception as e:
 
1003
  + "</pre>"
1004
  )
1005
  try:
1006
+ html = _pdf_preview_html(pdf_path, height="700px")
1007
  _write_logs(LOG_PATH, logs)
1008
  return html
1009
  except Exception as e:
 
1213
  try:
1214
  pdf_path = _compile_poster_pdf(OUTPUT_DIR, logs)
1215
  if pdf_path and pdf_path.exists():
1216
+ pdf_html = _pdf_preview_html(pdf_path)
1217
  compiled_pdf_file = str(pdf_path)
1218
  logs.append("🖨️ PDF ready for preview in UI.")
1219
  except Exception as e: