Spaces:
Sleeping
Sleeping
Hemanth-05 commited on
Commit Β·
79eb9e2
1
Parent(s): 9b69919
Added thread-based background ingestion worker
Browse files
app.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
"""NotebookLM β AI-Powered Study Companion (Gradio)."""
|
| 2 |
|
|
|
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
from state import (
|
|
@@ -42,6 +43,9 @@ from pages.artifacts import (
|
|
| 42 |
has_any_summary,
|
| 43 |
)
|
| 44 |
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
# ββ Helpers ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 47 |
|
|
@@ -514,6 +518,13 @@ with gr.Blocks(css=CUSTOM_CSS, theme=dark_theme, title="NotebookLM") as demo:
|
|
| 514 |
).then(fn=None, js=MARK_DIRTY_JS)
|
| 515 |
|
| 516 |
# ββ Sources: Process pending sources βββββββββββββββββββββββββββββββββββββ
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 517 |
def handle_process_sources(state):
|
| 518 |
nb = get_active_notebook(state)
|
| 519 |
if not nb:
|
|
@@ -529,13 +540,26 @@ with gr.Blocks(css=CUSTOM_CSS, theme=dark_theme, title="NotebookLM") as demo:
|
|
| 529 |
)
|
| 530 |
return refresh_all(state) + (msg,)
|
| 531 |
|
| 532 |
-
|
| 533 |
-
|
| 534 |
-
|
| 535 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 536 |
msg = (
|
| 537 |
'<p style="font-size:0.82rem; color:#22c55e; margin:6px 0 0 0;">'
|
| 538 |
-
|
| 539 |
'</p>'
|
| 540 |
)
|
| 541 |
return refresh_all(state) + (msg,)
|
|
|
|
| 1 |
"""NotebookLM β AI-Powered Study Companion (Gradio)."""
|
| 2 |
|
| 3 |
+
import threading
|
| 4 |
import gradio as gr
|
| 5 |
|
| 6 |
from state import (
|
|
|
|
| 43 |
has_any_summary,
|
| 44 |
)
|
| 45 |
|
| 46 |
+
_INGESTION_LOCK = threading.Lock()
|
| 47 |
+
_INGESTION_RUNNING_NOTEBOOKS: set[str] = set()
|
| 48 |
+
|
| 49 |
|
| 50 |
# ββ Helpers ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 51 |
|
|
|
|
| 518 |
).then(fn=None, js=MARK_DIRTY_JS)
|
| 519 |
|
| 520 |
# ββ Sources: Process pending sources βββββββββββββββββββββββββββββββββββββ
|
| 521 |
+
def _run_ingestion_background(state: UserData, notebook_id: str):
|
| 522 |
+
try:
|
| 523 |
+
run_ingestion_pipeline(state)
|
| 524 |
+
finally:
|
| 525 |
+
with _INGESTION_LOCK:
|
| 526 |
+
_INGESTION_RUNNING_NOTEBOOKS.discard(notebook_id)
|
| 527 |
+
|
| 528 |
def handle_process_sources(state):
|
| 529 |
nb = get_active_notebook(state)
|
| 530 |
if not nb:
|
|
|
|
| 540 |
)
|
| 541 |
return refresh_all(state) + (msg,)
|
| 542 |
|
| 543 |
+
with _INGESTION_LOCK:
|
| 544 |
+
if nb.id in _INGESTION_RUNNING_NOTEBOOKS:
|
| 545 |
+
msg = (
|
| 546 |
+
'<p style="font-size:0.82rem; color:#9090a8; margin:6px 0 0 0;">'
|
| 547 |
+
'Processing already running for this notebook.'
|
| 548 |
+
'</p>'
|
| 549 |
+
)
|
| 550 |
+
return refresh_all(state) + (msg,)
|
| 551 |
+
_INGESTION_RUNNING_NOTEBOOKS.add(nb.id)
|
| 552 |
+
|
| 553 |
+
worker = threading.Thread(
|
| 554 |
+
target=_run_ingestion_background,
|
| 555 |
+
args=(state, nb.id),
|
| 556 |
+
daemon=True,
|
| 557 |
+
)
|
| 558 |
+
worker.start()
|
| 559 |
+
|
| 560 |
msg = (
|
| 561 |
'<p style="font-size:0.82rem; color:#22c55e; margin:6px 0 0 0;">'
|
| 562 |
+
'Processing started in background. You can switch tabs; return to Sources to check status.'
|
| 563 |
'</p>'
|
| 564 |
)
|
| 565 |
return refresh_all(state) + (msg,)
|