internomega-terrablue Claude Sonnet 4.6 commited on
Commit
186f0f5
Β·
1 Parent(s): 5ff8379

fix: async ingestion with generator yield + chat history double-count

Browse files
Files changed (1) hide show
  1. app.py +15 -23
app.py CHANGED
@@ -476,38 +476,30 @@ with gr.Blocks(css=CUSTOM_CSS, theme=dark_theme, title="NotebookLM", js=BEFOREUN
476
  )
477
 
478
  # ── Sources: File upload ─────────────────────────────────────────────────
 
 
 
 
 
 
479
  file_uploader.upload(
480
- fn=handle_file_upload,
481
  inputs=[file_uploader, user_state],
482
- outputs=[user_state, source_list_html, source_header, source_selector],
483
- api_name=False,
484
- ).then(
485
- fn=run_ingestion_pipeline,
486
- inputs=[user_state],
487
- outputs=[user_state, source_list_html, source_header, source_selector],
488
- api_name=False,
489
- ).then(
490
- fn=refresh_all,
491
- inputs=[user_state],
492
  outputs=refresh_outputs,
493
  api_name=False,
494
  ).then(fn=None, js=MARK_DIRTY_JS)
495
 
496
  # ── Sources: Add URL ─────────────────────────────────────────────────────
 
 
 
 
 
 
497
  add_url_btn.click(
498
- fn=handle_url_add,
499
  inputs=[url_input, user_state],
500
- outputs=[user_state, source_list_html, source_header, url_input, source_selector],
501
- api_name=False,
502
- ).then(
503
- fn=run_ingestion_pipeline,
504
- inputs=[user_state],
505
- outputs=[user_state, source_list_html, source_header, source_selector],
506
- api_name=False,
507
- ).then(
508
- fn=refresh_all,
509
- inputs=[user_state],
510
- outputs=refresh_outputs,
511
  api_name=False,
512
  ).then(fn=None, js=MARK_DIRTY_JS)
513
 
 
476
  )
477
 
478
  # ── Sources: File upload ─────────────────────────────────────────────────
479
+ def handle_upload_and_ingest(files, state):
480
+ state, _, _, _ = handle_file_upload(files, state)
481
+ yield refresh_all(state) # UI updates immediately β€” sources show "Processing..."
482
+ run_ingestion_pipeline(state) # Slow: extract, chunk, embed
483
+ yield refresh_all(state) # UI updates again β€” sources show "Ready"
484
+
485
  file_uploader.upload(
486
+ fn=handle_upload_and_ingest,
487
  inputs=[file_uploader, user_state],
 
 
 
 
 
 
 
 
 
 
488
  outputs=refresh_outputs,
489
  api_name=False,
490
  ).then(fn=None, js=MARK_DIRTY_JS)
491
 
492
  # ── Sources: Add URL ─────────────────────────────────────────────────────
493
+ def handle_url_add_and_ingest(url, state):
494
+ state, _, _, _, _ = handle_url_add(url, state)
495
+ yield refresh_all(state) + ("",) # UI updates immediately + clear URL input
496
+ run_ingestion_pipeline(state) # Slow: extract, chunk, embed
497
+ yield refresh_all(state) + ("",) # UI updates again β€” source shows "Ready"
498
+
499
  add_url_btn.click(
500
+ fn=handle_url_add_and_ingest,
501
  inputs=[url_input, user_state],
502
+ outputs=refresh_outputs + [url_input],
 
 
 
 
 
 
 
 
 
 
503
  api_name=False,
504
  ).then(fn=None, js=MARK_DIRTY_JS)
505