zamal commited on
Commit
a5216ce
·
verified ·
1 Parent(s): 94f2e74

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -15
app.py CHANGED
@@ -359,7 +359,7 @@ MODEL_OPTIONS = [
359
  ]
360
 
361
  with gr.Blocks(css=CSS, theme=gr.themes.Soft()) as demo:
362
- # State to track extraction
363
  session_state = gr.State({})
364
 
365
  # ─── Welcome Screen ─────────────────────────────────────────────
@@ -374,6 +374,9 @@ with gr.Blocks(css=CSS, theme=gr.themes.Soft()) as demo:
374
  with gr.Column(visible=False) as app_col:
375
  gr.Markdown("## 📚 Multimodal Chat-PDF Playground")
376
 
 
 
 
377
  with gr.Tabs() as tabs:
378
  # ── Tab 1: Upload & Extract ───────────────────────────────
379
  with gr.TabItem("1. Upload & Extract"):
@@ -418,9 +421,8 @@ with gr.Blocks(css=CSS, theme=gr.themes.Soft()) as demo:
418
  )
419
  preview_html = gr.HTML()
420
 
421
- # 1) Run extraction
422
- # 2) When done, reveal the Chat tab
423
- extract_btn.click(
424
  fn=extract_data_from_pdfs,
425
  inputs=[
426
  docs,
@@ -431,23 +433,19 @@ with gr.Blocks(css=CSS, theme=gr.themes.Soft()) as demo:
431
  vlm_dd
432
  ],
433
  outputs=[
434
- session_state,
435
- preview_text,
436
- preview_img,
437
- preview_html
438
  ]
439
- ).then(
440
- fn=lambda: gr.update(visible=True),
441
- inputs=[],
442
- outputs=[tabs.select("2. Chat")]
443
  )
444
 
445
- # ── Tab 2: Chat (starts hidden) ────────────────────────────
446
  with gr.TabItem("2. Chat", visible=False) as chat_tab:
447
  with gr.Row():
448
  with gr.Column(scale=3):
449
  chat = gr.Chatbot(type="messages", label="Chat")
450
- msg = gr.Textbox(
451
  placeholder="Ask about your PDF...",
452
  label="Your question"
453
  )
@@ -477,11 +475,18 @@ with gr.Blocks(css=CSS, theme=gr.themes.Soft()) as demo:
477
  ],
478
  outputs=[
479
  chat,
480
- gr.Dataframe(),
481
  gr.Gallery(label="Relevant Images", rows=2, value=[])
482
  ]
483
  )
484
 
 
 
 
 
 
 
 
485
  gr.HTML("<center>Made with ❤️ by Zamal</center>")
486
 
487
  # ─── Wire the Start button ───────────────────────────────────────
@@ -493,3 +498,4 @@ with gr.Blocks(css=CSS, theme=gr.themes.Soft()) as demo:
493
 
494
  if __name__ == "__main__":
495
  demo.launch()
 
 
359
  ]
360
 
361
  with gr.Blocks(css=CSS, theme=gr.themes.Soft()) as demo:
362
+ # State to track that extraction completed (and carry any metadata)
363
  session_state = gr.State({})
364
 
365
  # ─── Welcome Screen ─────────────────────────────────────────────
 
374
  with gr.Column(visible=False) as app_col:
375
  gr.Markdown("## 📚 Multimodal Chat-PDF Playground")
376
 
377
+ # We need to capture the extract‐event so we can chain the “show chat tab” later
378
+ extract_event = None
379
+
380
  with gr.Tabs() as tabs:
381
  # ── Tab 1: Upload & Extract ───────────────────────────────
382
  with gr.TabItem("1. Upload & Extract"):
 
421
  )
422
  preview_html = gr.HTML()
423
 
424
+ # Kick off extraction and capture the event
425
+ extract_event = extract_btn.click(
 
426
  fn=extract_data_from_pdfs,
427
  inputs=[
428
  docs,
 
433
  vlm_dd
434
  ],
435
  outputs=[
436
+ session_state, # sets session["processed"]=True
437
+ preview_text, # shows first bits of text
438
+ preview_img, # shows first images
439
+ preview_html # shows “<h3>Done!</h3>”
440
  ]
 
 
 
 
441
  )
442
 
443
+ # ── Tab 2: Chat (initially hidden) ──────────────────────────
444
  with gr.TabItem("2. Chat", visible=False) as chat_tab:
445
  with gr.Row():
446
  with gr.Column(scale=3):
447
  chat = gr.Chatbot(type="messages", label="Chat")
448
+ msg = gr.Textbox(
449
  placeholder="Ask about your PDF...",
450
  label="Your question"
451
  )
 
475
  ],
476
  outputs=[
477
  chat,
478
+ gr.Dataframe(), # shows retrieved text chunks
479
  gr.Gallery(label="Relevant Images", rows=2, value=[])
480
  ]
481
  )
482
 
483
+ # After both tabs are defined, chain the “unhide chat tab” event
484
+ extract_event.then(
485
+ fn=lambda: gr.update(visible=True),
486
+ inputs=[],
487
+ outputs=[chat_tab]
488
+ )
489
+
490
  gr.HTML("<center>Made with ❤️ by Zamal</center>")
491
 
492
  # ─── Wire the Start button ───────────────────────────────────────
 
498
 
499
  if __name__ == "__main__":
500
  demo.launch()
501
+