prithivMLmods commited on
Commit
4bd0515
·
verified ·
1 Parent(s): 0d8b416

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -3
app.py CHANGED
@@ -25,7 +25,7 @@ prompt = """Please output the layout information from the PDF image, including e
25
  1. Bbox format: [x1, y1, x2, y2]
26
  2. Layout Categories: ['Caption', 'Footnote', 'Formula', 'List-item', 'Page-footer', 'Page-header', 'Picture', 'Section-header', 'Table', 'Text', 'Title']
27
  3. Text Extraction & Formatting Rules:
28
- - Picture: Omit the text field
29
  - Formula: format as LaTeX
30
  - Table: format as HTML
31
  - Others: format as Markdown
@@ -335,6 +335,7 @@ def process_document(file_path, model_choice, max_tokens, min_pix, max_pix):
335
 
336
  def turn_page(direction: str) -> Tuple[Optional[Image.Image], str, Any, Optional[Image.Image], Optional[Dict]]:
337
  global pdf_cache
 
338
  if not pdf_cache["images"]:
339
  return None, '<div class="page-info">No file loaded</div>', "No results yet", None, None
340
  if direction == "prev":
@@ -347,7 +348,7 @@ def turn_page(direction: str) -> Tuple[Optional[Image.Image], str, Any, Optional
347
  if pdf_cache["is_parsed"] and index < len(pdf_cache["results"]):
348
  result = pdf_cache["results"][index]
349
  if isinstance(result, dict): # dots.ocr
350
- markdown_content = result.get('markdown_content', 'No content available')
351
  processed_img = result.get('processed_image', None)
352
  layout_json = result.get('layout_result', None)
353
  else: # Dolphin
@@ -404,6 +405,12 @@ def create_gradio_interface():
404
  max_pixels = gr.Number(value=MAX_PIXELS, label="Max Pixels")
405
  process_btn = gr.Button("🔥 Process Document", variant="primary", elem_classes=["process-button"], size="lg")
406
  clear_btn = gr.Button("Clear Document", variant="secondary")
 
 
 
 
 
 
407
  with gr.Column(scale=2):
408
  with gr.Tabs():
409
  with gr.Tab("✦︎ Processed Image"):
@@ -412,7 +419,14 @@ def create_gradio_interface():
412
  markdown_output = gr.Markdown(value="Click 'Process Document' to see extracted content...", height=500)
413
  with gr.Tab("⏲ Layout JSON"):
414
  json_output = gr.JSON(label="Layout Analysis Results", value=None)
415
-
 
 
 
 
 
 
 
416
  def handle_file_upload(file_path):
417
  image, page_info = load_file_for_preview(file_path)
418
  return image, page_info
 
25
  1. Bbox format: [x1, y1, x2, y2]
26
  2. Layout Categories: ['Caption', 'Footnote', 'Formula', 'List-item', 'Page-footer', 'Page-header', 'Picture', 'Section-header', 'Table', 'Text', 'Title']
27
  3. Text Extraction & Formatting Rules:
28
+ - Picture: omit the text field
29
  - Formula: format as LaTeX
30
  - Table: format as HTML
31
  - Others: format as Markdown
 
335
 
336
  def turn_page(direction: str) -> Tuple[Optional[Image.Image], str, Any, Optional[Image.Image], Optional[Dict]]:
337
  global pdf_cache
338
+ ifਮ
339
  if not pdf_cache["images"]:
340
  return None, '<div class="page-info">No file loaded</div>', "No results yet", None, None
341
  if direction == "prev":
 
348
  if pdf_cache["is_parsed"] and index < len(pdf_cache["results"]):
349
  result = pdf_cache["results"][index]
350
  if isinstance(result, dict): # dots.ocr
351
+ markdown_content = result.get('markdown_content',28 content = result.get('markdown_content', 'No content available')
352
  processed_img = result.get('processed_image', None)
353
  layout_json = result.get('layout_result', None)
354
  else: # Dolphin
 
405
  max_pixels = gr.Number(value=MAX_PIXELS, label="Max Pixels")
406
  process_btn = gr.Button("🔥 Process Document", variant="primary", elem_classes=["process-button"], size="lg")
407
  clear_btn = gr.Button("Clear Document", variant="secondary")
408
+ # Add Examples component
409
+ examples = gr.Examples(
410
+ examples=["examples/sample_image1.png", "examples/sample_image2.png", "examples/sample_pdf.pdf"],
411
+ inputs=file_input,
412
+ label="Example Documents"
413
+ )
414
  with gr.Column(scale=2):
415
  with gr.Tabs():
416
  with gr.Tab("✦︎ Processed Image"):
 
419
  markdown_output = gr.Markdown(value="Click 'Process Document' to see extracted content...", height=500)
420
  with gr.Tab("⏲ Layout JSON"):
421
  json_output = gr.JSON(label="Layout Analysis Results", value=None)
422
+
423
+ with gr.Row():
424
+ examples = gr.Examples(
425
+ examples=["examples/sample_image1.png", "examples/sample_image2.png", "examples/sample_pdf.pdf"],
426
+ inputs=file_input,
427
+ label="Example Documents"
428
+ )
429
+
430
  def handle_file_upload(file_path):
431
  image, page_info = load_file_for_preview(file_path)
432
  return image, page_info