aadisawant2912 commited on
Commit
7513bc8
Β·
verified Β·
1 Parent(s): d8cf9de

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +86 -1
app.py CHANGED
@@ -249,6 +249,40 @@ def handle_file_upload(file_path) -> str:
249
  return msg + "Type 'run abstract' in the chat to begin."
250
 
251
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
252
  def _detect_phase(text: str) -> int:
253
  phase_map = {
254
  "phase 5.5": 5, "phase 6": 6, "phase 5": 4,
@@ -521,7 +555,45 @@ with gr.Blocks(title="BERTopic Thematic Analysis Agent") as demo:
521
 
522
  # ── Section 1 ─────────────────────────────────────────────────────────────
523
  with gr.Accordion("πŸ“‚ Section 1 β€” Data Input", open=True):
524
- file_input = gr.File(label="Upload Scopus CSV", file_types=[".csv"], type="filepath")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
525
  file_status = gr.Textbox(
526
  label="Upload status", interactive=False, lines=2,
527
  )
@@ -631,6 +703,14 @@ with gr.Blocks(title="BERTopic Thematic Analysis Agent") as demo:
631
  abstract_thread_state, title_thread_state, current_run_state,
632
  ]
633
 
 
 
 
 
 
 
 
 
634
  send_btn.click(
635
  fn=run_agent,
636
  inputs=[chat_input, chatbot,
@@ -649,6 +729,11 @@ with gr.Blocks(title="BERTopic Thematic Analysis Agent") as demo:
649
  abstract_thread_state, title_thread_state, current_run_state],
650
  outputs=send_outputs,
651
  )
 
 
 
 
 
652
 
653
  print("Step 5: UI built OK, launching...")
654
 
 
249
  return msg + "Type 'run abstract' in the chat to begin."
250
 
251
 
252
+ def reset_all_data() -> tuple:
253
+ """
254
+ Delete everything in data/ so the user can start a completely fresh run.
255
+ Returns updated UI state for all outputs.
256
+ """
257
+ import shutil as _shutil
258
+ # Remove the entire data directory and recreate empty
259
+ if DATA_DIR.exists():
260
+ _shutil.rmtree(str(DATA_DIR))
261
+ DATA_DIR.mkdir(exist_ok=True)
262
+ empty_df = pd.DataFrame(columns=REVIEW_COLUMNS)
263
+ empty_chart = "<p style='color:#9ca3af;padding:20px;'>Charts appear after Phase 2 completes.</p>"
264
+ status_msg = (
265
+ "<div style='padding:10px;background:#fef3c7;border-radius:6px;"
266
+ "font-family:sans-serif;font-size:13px;'>"
267
+ "πŸ”„ <b>All data cleared.</b> Upload a new CSV and type <b>run abstract</b> to begin."
268
+ "</div>"
269
+ )
270
+ return (
271
+ [], # chatbot history cleared
272
+ "", # chat input cleared
273
+ make_progress_html(0), # progress reset
274
+ _run_status_html(), # status badges reset
275
+ empty_df, # review table cleared
276
+ empty_chart, # chart cleared
277
+ None, # downloads cleared
278
+ new_thread_id(), # fresh abstract thread
279
+ new_thread_id(), # fresh title thread
280
+ "abstract", # reset current run
281
+ status_msg, # table status message
282
+ "", # file status cleared
283
+ )
284
+
285
+
286
  def _detect_phase(text: str) -> int:
287
  phase_map = {
288
  "phase 5.5": 5, "phase 6": 6, "phase 5": 4,
 
555
 
556
  # ── Section 1 ─────────────────────────────────────────────────────────────
557
  with gr.Accordion("πŸ“‚ Section 1 β€” Data Input", open=True):
558
+
559
+ # Show existing data state on load
560
+ def _startup_msg():
561
+ abs_done = (DATA_DIR / "abstract" / "taxonomy.json").exists()
562
+ title_done = (DATA_DIR / "title" / "taxonomy.json").exists()
563
+ csv_exists = (DATA_DIR / "uploaded.csv").exists()
564
+ has_data = csv_exists or abs_done or title_done
565
+ return (
566
+ "<div style='padding:10px;background:#fef3c7;border:1px solid #fcd34d;"
567
+ "border-radius:8px;font-family:sans-serif;font-size:13px;'>"
568
+ "⚠️ <b>Previous session data detected.</b> "
569
+ "Abstract run: {abs} &nbsp;|&nbsp; Title run: {title} &nbsp;|&nbsp; CSV: {csv}<br>"
570
+ "Click <b>πŸ—‘οΈ Reset & Start Fresh</b> to clear everything and begin a new analysis. "
571
+ "Or continue where you left off by typing your next command."
572
+ "</div>"
573
+ if has_data else
574
+ "<div style='padding:10px;background:#f0fdf4;border:1px solid #86efac;"
575
+ "border-radius:8px;font-family:sans-serif;font-size:13px;'>"
576
+ "βœ… Fresh session β€” no previous data. Upload your CSV to begin."
577
+ "</div>"
578
+ ).format(
579
+ abs="βœ…" if abs_done else "⏳",
580
+ title="βœ…" if title_done else "⏳",
581
+ csv="βœ…" if csv_exists else "❌",
582
+ )
583
+
584
+ startup_banner = gr.HTML(_startup_msg())
585
+
586
+ with gr.Row():
587
+ file_input = gr.File(
588
+ label="Upload Scopus CSV", file_types=[".csv"],
589
+ type="filepath", scale=4,
590
+ )
591
+ reset_btn = gr.Button(
592
+ "πŸ—‘οΈ Reset & Start Fresh",
593
+ variant="stop", scale=1,
594
+ size="sm",
595
+ )
596
+
597
  file_status = gr.Textbox(
598
  label="Upload status", interactive=False, lines=2,
599
  )
 
703
  abstract_thread_state, title_thread_state, current_run_state,
704
  ]
705
 
706
+ # Reset wires to ALL outputs including table_status, file_status, startup_banner
707
+ reset_outputs = [
708
+ chatbot, chat_input, progress_bar, run_status,
709
+ review_table, chart_display, download_files,
710
+ abstract_thread_state, title_thread_state, current_run_state,
711
+ table_status, file_status,
712
+ ]
713
+
714
  send_btn.click(
715
  fn=run_agent,
716
  inputs=[chat_input, chatbot,
 
729
  abstract_thread_state, title_thread_state, current_run_state],
730
  outputs=send_outputs,
731
  )
732
+ reset_btn.click(
733
+ fn=reset_all_data,
734
+ inputs=[],
735
+ outputs=reset_outputs,
736
+ )
737
 
738
  print("Step 5: UI built OK, launching...")
739