broadfield-dev commited on
Commit
91346a6
Β·
verified Β·
1 Parent(s): 0a13d87

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +172 -46
app.py CHANGED
@@ -396,62 +396,184 @@ def ui_upload_memories_action_fn(uploaded_file_obj, progress=gr.Progress()):
396
  msg = f"Memories Upload: Processed {total_to_process}. Added: {added_count}, Format Errors: {format_error_count}, Save Errors: {save_error_count}."
397
  logger.info(msg); return msg
398
 
 
 
 
399
  custom_theme = gr.themes.Base(primary_hue="teal", secondary_hue="purple", neutral_hue="zinc", text_size="sm", spacing_size="md", radius_size="sm", font=["System UI", "sans-serif"])
400
  custom_css = """
401
- #component-0 {gap:0 !important;}
402
- body { background: linear-gradient(to bottom right, #2c3e50, #34495e); color: #ecf0f1; min-height: 100vh; margin:0; padding:0;}
403
- .gradio-container { background: transparent !important; max-width: 100% !important; padding: 1rem !important; box-sizing: border-box;}
404
- .gr-box, .gr-panel, .gr-tabs, .gr-accordion { background-color: rgba(44, 62, 80, 0.85) !important; border: 1px solid rgba(189, 195, 199, 0.2) !important; border-radius: 8px !important; box-shadow: 0 4px 6px rgba(0,0,0,0.1);}
405
- .gr-tabitem { background-color: rgba(52, 73, 94, 0.7) !important; border-radius: 6px !important; margin-bottom: 5px !important; padding: 1em !important;}
406
- .gr-textbox, .gr-dropdown, .gr-button, .gr-code, .gr-chat-message, .gr-json, .gr-file input[type="file"] { border: 1px solid rgba(189, 195, 199, 0.3) !important; background-color: rgba(52, 73, 94, 0.9) !important; color: #ecf0f1 !important; border-radius: 6px !important;}
407
- .gr-file { background-color: rgba(52, 73, 94, 0.9) !important; border-radius: 6px !important; padding: 0.5em;}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
408
  .gr-file > .label-text { color: #bdc3c7 !important;}
409
  .gr-textarea textarea, .gr-textbox input { color: #ecf0f1 !important; }
 
410
  .gr-button.gr-button-primary { background-color: #1abc9c !important; color: white !important; border-color: #16a085 !important; }
411
  .gr-button.gr-button-secondary { background-color: #9b59b6 !important; color: white !important; border-color: #8e44ad !important; }
412
  .gr-button.gr-button-stop { background-color: #e74c3c !important; color: white !important; border-color: #c0392b !important; }
413
- .gr-markdown { background-color: transparent !important; padding: 0px; }
414
- .gr-markdown h1, .gr-markdown h2, .gr-markdown h3 { color: #1abc9c !important; border-bottom: 1px solid rgba(189, 195, 199, 0.2) !important; padding-bottom: 0.3em; margin-top:1em; }
 
 
 
 
 
 
 
415
  .gr-markdown p, .gr-markdown li { color: #ecf0f1 !important; }
416
- .gr-markdown pre code { background-color: rgba(30, 40, 50, 0.95) !important; border: 1px solid rgba(189, 195, 199, 0.3) !important; color: #ecf0f1; border-radius: 4px; padding: 0.8em; }
417
- .gr-chatbot { background-color: rgba(44, 62, 80, 0.7) !important; border: 1px solid rgba(189, 195, 199, 0.2) !important; }
418
- .gr-chatbot .message { background-color: rgba(52, 73, 94, 0.9) !important; color: #ecf0f1 !important; border: 1px solid rgba(189, 195, 199, 0.2) !important; box-shadow: 0 1px 2px rgba(0,0,0,0.1) !important; }
419
- .gr-chatbot .message.user { background-color: rgba(46, 204, 113, 0.8) !important; color: #2c3e50 !important; }
420
- .gr-input-label > .label-text, .gr-dropdown-label > .label-text, .gr-checkbox-label > .label-text { color: #bdc3c7 !important; font-size: 0.9rem !important; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
421
  .gr-info { color: #bdc3c7 !important; font-size: 0.85rem !important; }
422
- #status_bar_group { background-color: rgba(44, 62, 80, 0.8) !important; padding: 8px; border-radius: 6px; margin-bottom: 10px; }
423
- .tabnav button { background-color: rgba(52, 73, 94, 0.8) !important; color: #ecf0f1 !important; border-bottom: 2px solid transparent !important;}
424
- .tabnav button.selected { background-color: rgba(44, 62, 80, 0.95) !important; color: #1abc9c !important; border-bottom: 2px solid #1abc9c !important;}
425
- .gr-block.gr-box { padding: 1em; } /* Add some padding to groups/boxes */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
426
  """
427
 
428
- with gr.Blocks(theme=custom_theme, css=custom_css, title="AI Research Mega Agent v5.2") as demo:
429
- gr.Markdown("# πŸš€ AI Research Mega Agent Dashboard")
 
 
430
 
431
  avail_provs = get_available_providers()
432
  def_prov = avail_provs[0] if avail_provs else None
433
  def_models = get_model_display_names_for_provider(def_prov) if def_prov else []
434
  def_model_disp = get_default_model_display_name_for_provider(def_prov) if def_prov else None
435
 
436
- with gr.Row(elem_id="status_bar_group"):
 
437
  with gr.Column(scale=3): agent_stat_tb = gr.Textbox(label="Agent Status", interactive=False, lines=1, value="Initializing systems...")
438
  with gr.Column(scale=1): memory_backend_info_tb = gr.Textbox(label="Memory Backend", value=f"{MEMORY_STORAGE_BACKEND}", interactive=False)
439
  if MEMORY_STORAGE_BACKEND == "SQLITE":
440
- with gr.Column(scale=2): gr.Textbox(label="SQLite Path", value=f"{MEMORY_SQLITE_PATH}", interactive=False)
441
  elif MEMORY_STORAGE_BACKEND == "HF_DATASET":
442
- with gr.Column(scale=2): gr.Textbox(label="HF Repos", value=f"M: {MEMORY_HF_MEM_REPO}, R: {MEMORY_HF_RULES_REPO}", interactive=False)
443
 
444
  with gr.Tabs() as main_tabs:
445
- with gr.TabItem("βš™οΈ Config & πŸ’¬ Chat", id=0):
446
- with gr.Row(equal_height=False):
447
  with gr.Column(scale=1, min_width=380): # Sidebar for config
448
  gr.Markdown("## βš™οΈ LLM Configuration")
449
- with gr.Group():
450
  prov_sel_dd = gr.Dropdown(label="AI Provider", choices=avail_provs, value=def_prov, interactive=True)
451
  model_sel_dd = gr.Dropdown(label="AI Model", choices=def_models, value=def_model_disp, interactive=True)
452
  api_key_tb = gr.Textbox(label="API Key Override (Optional)", type="password", placeholder="Paste key for selected provider")
453
  with gr.Group():
454
- sys_prompt_tb = gr.Textbox(label="System Prompt Base", lines=12, value=DEFAULT_SYSTEM_PROMPT, interactive=True)
455
 
456
  with gr.Column(scale=2): # Main chat area
457
  gr.Markdown("## πŸ’¬ AI Chat Interface")
@@ -460,33 +582,36 @@ with gr.Blocks(theme=custom_theme, css=custom_css, title="AI Research Mega Agent
460
  user_msg_tb = gr.Textbox(show_label=False, placeholder="Ask your research question or give an instruction...", scale=7, lines=1, max_lines=5, autofocus=True)
461
  send_btn = gr.Button("Send", variant="primary", scale=1, min_width=100)
462
 
463
- with gr.Accordion("πŸ“ Full Response / Output Details", open=False, elem_id="response_accordion"):
464
  fmt_report_tb = gr.Textbox(label="Full AI Response", lines=10, interactive=True, show_copy_button=True, value="*AI responses will appear here...*")
465
  dl_report_btn = gr.DownloadButton("Download Report", interactive=False, visible=False)
466
  detect_out_md = gr.Markdown("*Insights used or other intermediate details will show here...*")
467
 
468
  with gr.TabItem("🧠 Knowledge Base Management", id=1):
469
- gr.Markdown("## Manage Stored Knowledge")
470
  with gr.Row(equal_height=False):
471
  with gr.Column(scale=1):
472
- gr.Markdown("### πŸ“œ Rules (Learned Insights)")
473
- rules_disp_ta = gr.TextArea(label="View/Edit Rules (one per line or '---' separated)", lines=15, interactive=True, placeholder="Load or type rules here...")
474
- with gr.Row():
475
- view_rules_btn = gr.Button("πŸ”„ Load/Refresh Rules"); save_edited_rules_btn = gr.Button("πŸ’Ύ Save Edited Rules", variant="primary")
476
- upload_rules_fobj = gr.File(label="Upload Rules File (.txt or .jsonl)", file_types=[".txt", ".jsonl"])
477
- rules_stat_tb = gr.Textbox(label="Rules Operation Status", interactive=False, lines=2, placeholder="Status of rule operations...")
478
- with gr.Row():
479
- clear_rules_btn = gr.Button("⚠️ Clear All Rules", variant="stop")
480
- save_faiss_ram_btn_kb = gr.Button("Save FAISS Indices", visible=(MEMORY_STORAGE_BACKEND == "RAM"))
 
481
 
482
  with gr.Column(scale=1):
483
- gr.Markdown("### πŸ“š Memories (Past Interactions)")
484
- mems_disp_json = gr.JSON(label="View Memories (JSON format)", scale=2) # scale might not work directly on gr.JSON
485
- with gr.Row(): view_mems_btn = gr.Button("πŸ”„ Load/Refresh Memories")
486
- upload_mems_fobj = gr.File(label="Upload Memories File (.jsonl)", file_types=[".jsonl"])
487
- mems_stat_tb = gr.Textbox(label="Memories Operation Status", interactive=False, lines=2, placeholder="Status of memory operations...")
488
- clear_mems_btn = gr.Button("⚠️ Clear All Memories", variant="stop")
 
489
 
 
490
  def dyn_upd_model_dd(sel_prov_dyn:str): models_dyn, def_model_dyn = get_model_display_names_for_provider(sel_prov_dyn), get_default_model_display_name_for_provider(sel_prov_dyn); return gr.Dropdown(choices=models_dyn, value=def_model_dyn, interactive=True)
491
  prov_sel_dd.change(fn=dyn_upd_model_dd, inputs=prov_sel_dd, outputs=model_sel_dd)
492
  chat_ins = [user_msg_tb, main_chat_disp, prov_sel_dd, model_sel_dd, api_key_tb, sys_prompt_tb]
@@ -532,10 +657,11 @@ with gr.Blocks(theme=custom_theme, css=custom_css, title="AI Research Mega Agent
532
 
533
  demo.load(fn=app_load_fn, inputs=None, outputs=[agent_stat_tb, rules_disp_ta, mems_disp_json])
534
 
 
535
  if __name__ == "__main__":
536
- logger.info(f"Starting Gradio AI Research Mega Agent (v5.2 with Dashboard UI & Advanced Memory: {MEMORY_STORAGE_BACKEND})...")
537
  app_port, app_server = int(os.getenv("GRADIO_PORT", 7860)), os.getenv("GRADIO_SERVER_NAME", "127.0.0.1")
538
  app_debug, app_share = os.getenv("GRADIO_DEBUG", "False").lower()=="true", os.getenv("GRADIO_SHARE", "False").lower()=="true"
539
  logger.info(f"Launching Gradio server: http://{app_server}:{app_port}. Debug: {app_debug}, Share: {app_share}")
540
- demo.queue().launch(server_name=app_server, server_port=app_port, debug=app_debug, share=app_share)
541
  logger.info("Gradio application shut down.")
 
396
  msg = f"Memories Upload: Processed {total_to_process}. Added: {added_count}, Format Errors: {format_error_count}, Save Errors: {save_error_count}."
397
  logger.info(msg); return msg
398
 
399
+ # app.py
400
+ # ... (all other Python code remains the same) ...
401
+
402
  custom_theme = gr.themes.Base(primary_hue="teal", secondary_hue="purple", neutral_hue="zinc", text_size="sm", spacing_size="md", radius_size="sm", font=["System UI", "sans-serif"])
403
  custom_css = """
404
+ html, body { /* Reset browser defaults for html and body */
405
+ margin: 0 !important;
406
+ padding: 0 !important;
407
+ height: 100%; /* Ensure body can fill height if needed */
408
+ box-sizing: border-box; /* Better box model */
409
+ }
410
+ *, *:before, *:after { /* Apply box-sizing to all elements */
411
+ box-sizing: inherit;
412
+ }
413
+
414
+ body {
415
+ background: linear-gradient(to bottom right, #2c3e50, #34495e);
416
+ color: #ecf0f1;
417
+ min-height: 100vh; /* Ensure body takes at least full viewport height */
418
+ font-family: 'Inter', sans-serif; /* Moved font-family here for global effect */
419
+ }
420
+
421
+ .gradio-container {
422
+ background: transparent !important;
423
+ max-width: 100% !important; /* Use 100% to avoid slight gaps on sides sometimes seen with 98/96% */
424
+ padding: 1rem !important; /* Ensure some padding around the content */
425
+ margin: 0 auto !important; /* Center if max-width was less than 100% */
426
+ min-height: 100vh; /* Make container also try to fill height */
427
+ display: flex; /* Helps with some layout consistencies */
428
+ flex-direction: column; /* Stack children vertically */
429
+ }
430
+
431
+ /* Target the very first direct child block of gradio-container to remove top margin if any */
432
+ .gradio-container > .gr-block:first-child {
433
+ margin-top: 0 !important;
434
+ }
435
+
436
+ /* Target the main title markdown specifically if it's causing issues */
437
+ .gradio-container > .gr-block.gr-markdown:first-child h1:first-child {
438
+ margin-top: 0 !important;
439
+ padding-top: 0 !important; /* Also try padding */
440
+ }
441
+
442
+
443
+ .gr-box, .gr-panel, .gr-tabs, .gr-accordion {
444
+ background-color: rgba(44, 62, 80, 0.85) !important;
445
+ border: 1px solid rgba(189, 195, 199, 0.2) !important;
446
+ border-radius: 8px !important;
447
+ box-shadow: 0 4px 6px rgba(0,0,0,0.1);
448
+ }
449
+ .gr-tabitem {
450
+ background-color: rgba(52, 73, 94, 0.7) !important;
451
+ border-radius: 6px !important;
452
+ margin-bottom: 5px !important;
453
+ padding: 1em !important;
454
+ }
455
+
456
+ .gr-textbox, .gr-dropdown, .gr-button, .gr-code, .gr-chat-message, .gr-json, .gr-file input[type="file"] {
457
+ border: 1px solid rgba(189, 195, 199, 0.3) !important;
458
+ background-color: rgba(52, 73, 94, 0.9) !important;
459
+ color: #ecf0f1 !important;
460
+ border-radius: 6px !important;
461
+ }
462
+ .gr-file {
463
+ background-color: rgba(52, 73, 94, 0.9) !important;
464
+ border-radius: 6px !important; padding: 0.5em;
465
+ }
466
  .gr-file > .label-text { color: #bdc3c7 !important;}
467
  .gr-textarea textarea, .gr-textbox input { color: #ecf0f1 !important; }
468
+
469
  .gr-button.gr-button-primary { background-color: #1abc9c !important; color: white !important; border-color: #16a085 !important; }
470
  .gr-button.gr-button-secondary { background-color: #9b59b6 !important; color: white !important; border-color: #8e44ad !important; }
471
  .gr-button.gr-button-stop { background-color: #e74c3c !important; color: white !important; border-color: #c0392b !important; }
472
+
473
+ .gr-markdown { background-color: transparent !important; padding: 0px; } /* Make markdown itself transparent if inside a styled box */
474
+ .gr-markdown h1, .gr-markdown h2, .gr-markdown h3 {
475
+ color: #1abc9c !important;
476
+ border-bottom: 1px solid rgba(189, 195, 199, 0.2) !important;
477
+ padding-bottom: 0.3em;
478
+ margin-top: 0.8em; /* Adjust default top margin for headers within markdown */
479
+ margin-bottom: 0.5em;
480
+ }
481
  .gr-markdown p, .gr-markdown li { color: #ecf0f1 !important; }
482
+ .gr-markdown pre code {
483
+ background-color: rgba(30, 40, 50, 0.95) !important;
484
+ border: 1px solid rgba(189, 195, 199, 0.3) !important;
485
+ color: #ecf0f1;
486
+ border-radius: 4px; padding: 0.8em;
487
+ }
488
+
489
+ .gr-chatbot {
490
+ background-color: rgba(44, 62, 80, 0.7) !important;
491
+ border: 1px solid rgba(189, 195, 199, 0.2) !important;
492
+ }
493
+ .gr-chatbot .message {
494
+ background-color: rgba(52, 73, 94, 0.9) !important;
495
+ color: #ecf0f1 !important;
496
+ border: 1px solid rgba(189, 195, 199, 0.2) !important;
497
+ box-shadow: 0 1px 2px rgba(0,0,0,0.1) !important;
498
+ }
499
+ .gr-chatbot .message.user {
500
+ background-color: rgba(46, 204, 113, 0.8) !important;
501
+ color: #2c3e50 !important;
502
+ }
503
+
504
+ .gr-input-label > .label-text, .gr-dropdown-label > .label-text, .gr-checkbox-label > .label-text {
505
+ color: #bdc3c7 !important;
506
+ font-size: 0.9rem !important;
507
+ }
508
  .gr-info { color: #bdc3c7 !important; font-size: 0.85rem !important; }
509
+
510
+ #status_bar_group { /* Renamed from elem_id to elem_classes if Gradio prefers that for styling groups */
511
+ background-color: rgba(44, 62, 80, 0.8) !important;
512
+ padding: 8px;
513
+ border-radius: 6px;
514
+ margin-bottom: 10px;
515
+ }
516
+ /* If using elem_classes="status-bar-group" on the gr.Row instead of elem_id */
517
+ .status-bar-group {
518
+ background-color: rgba(44, 62, 80, 0.8) !important;
519
+ padding: 8px;
520
+ border-radius: 6px;
521
+ margin-bottom: 10px;
522
+ }
523
+
524
+
525
+ .tabnav button { /* Style for tab buttons */
526
+ background-color: rgba(52, 73, 94, 0.8) !important;
527
+ color: #ecf0f1 !important;
528
+ border-bottom: 2px solid transparent !important;
529
+ border-top-left-radius: 6px !important; /* Slightly rounded top corners */
530
+ border-top-right-radius: 6px !important;
531
+ margin-right: 2px !important; /* Small gap between tab buttons */
532
+ }
533
+ .tabnav button.selected {
534
+ background-color: rgba(44, 62, 80, 0.95) !important; /* Match tab content background */
535
+ color: #1abc9c !important;
536
+ border-bottom: 2px solid #1abc9c !important;
537
+ }
538
+
539
+ .gr-block.gr-box { padding: 1em; } /* General padding for groups/boxes */
540
+
541
+ /* Ensure the main title Markdown doesn't have excessive top margin */
542
+ .gradio-container > .gr-block.gr-markdown:first-of-type h1 {
543
+ margin-top: 0 !important; /* This is more specific */
544
+ }
545
  """
546
 
547
+
548
+
549
+ with gr.Blocks(theme=custom_theme, css=custom_css, title="AI Research Mega Agent v5.3") as demo:
550
+ gr.Markdown("# πŸš€ AI Research Mega Agent Dashboard") # This is the first visible element
551
 
552
  avail_provs = get_available_providers()
553
  def_prov = avail_provs[0] if avail_provs else None
554
  def_models = get_model_display_names_for_provider(def_prov) if def_prov else []
555
  def_model_disp = get_default_model_display_name_for_provider(def_prov) if def_prov else None
556
 
557
+ # Moved status bar below the main title for better flow
558
+ with gr.Row(elem_classes="status-bar-group"): # Use elem_classes for easier targeting
559
  with gr.Column(scale=3): agent_stat_tb = gr.Textbox(label="Agent Status", interactive=False, lines=1, value="Initializing systems...")
560
  with gr.Column(scale=1): memory_backend_info_tb = gr.Textbox(label="Memory Backend", value=f"{MEMORY_STORAGE_BACKEND}", interactive=False)
561
  if MEMORY_STORAGE_BACKEND == "SQLITE":
562
+ with gr.Column(scale=2): gr.Textbox(label="SQLite Path", value=f"{MEMORY_SQLITE_PATH}", interactive=False, elem_id="sqlite_path_display") # Added elem_id for potential specific styling
563
  elif MEMORY_STORAGE_BACKEND == "HF_DATASET":
564
+ with gr.Column(scale=2): gr.Textbox(label="HF Repos", value=f"M: {MEMORY_HF_MEM_REPO}, R: {MEMORY_HF_RULES_REPO}", interactive=False, elem_id="hf_repos_display")
565
 
566
  with gr.Tabs() as main_tabs:
567
+ with gr.TabItem("βš™οΈ Agent Configuration & πŸ’¬ Chat", id=0): # Combined Config and Chat
568
+ with gr.Row(equal_height=False): # Allow columns to size independently
569
  with gr.Column(scale=1, min_width=380): # Sidebar for config
570
  gr.Markdown("## βš™οΈ LLM Configuration")
571
+ with gr.Group(): # Removed elem_classes="compact-group" unless specifically needed for sub-styling
572
  prov_sel_dd = gr.Dropdown(label="AI Provider", choices=avail_provs, value=def_prov, interactive=True)
573
  model_sel_dd = gr.Dropdown(label="AI Model", choices=def_models, value=def_model_disp, interactive=True)
574
  api_key_tb = gr.Textbox(label="API Key Override (Optional)", type="password", placeholder="Paste key for selected provider")
575
  with gr.Group():
576
+ sys_prompt_tb = gr.Textbox(label="System Prompt Base", lines=10, value=DEFAULT_SYSTEM_PROMPT, interactive=True)
577
 
578
  with gr.Column(scale=2): # Main chat area
579
  gr.Markdown("## πŸ’¬ AI Chat Interface")
 
582
  user_msg_tb = gr.Textbox(show_label=False, placeholder="Ask your research question or give an instruction...", scale=7, lines=1, max_lines=5, autofocus=True)
583
  send_btn = gr.Button("Send", variant="primary", scale=1, min_width=100)
584
 
585
+ with gr.Accordion("πŸ“ Full Response / Output Details", open=False): # Initially closed
586
  fmt_report_tb = gr.Textbox(label="Full AI Response", lines=10, interactive=True, show_copy_button=True, value="*AI responses will appear here...*")
587
  dl_report_btn = gr.DownloadButton("Download Report", interactive=False, visible=False)
588
  detect_out_md = gr.Markdown("*Insights used or other intermediate details will show here...*")
589
 
590
  with gr.TabItem("🧠 Knowledge Base Management", id=1):
591
+ gr.Markdown("## Manage Stored Knowledge") # Top level header for the tab
592
  with gr.Row(equal_height=False):
593
  with gr.Column(scale=1):
594
+ with gr.Box(): # Using Box for a slightly more contained look
595
+ gr.Markdown("### πŸ“œ Rules (Learned Insights)")
596
+ rules_disp_ta = gr.TextArea(label="View/Edit Rules", lines=15, interactive=True, placeholder="Load or type rules here (one per line or '---' separated for multiple).")
597
+ with gr.Row():
598
+ view_rules_btn = gr.Button("πŸ”„ Load/Refresh Rules View"); save_edited_rules_btn = gr.Button("πŸ’Ύ Save Edited Rules", variant="primary")
599
+ upload_rules_fobj = gr.File(label="Upload Rules File (.txt/.jsonl)", file_types=[".txt", ".jsonl"])
600
+ rules_stat_tb = gr.Textbox(label="Rules Operation Status", interactive=False, lines=2, placeholder="Status of rule operations...")
601
+ with gr.Row():
602
+ clear_rules_btn = gr.Button("⚠️ Clear All Rules", variant="stop")
603
+ save_faiss_ram_btn_kb = gr.Button("Save FAISS Indices", visible=(MEMORY_STORAGE_BACKEND == "RAM"))
604
 
605
  with gr.Column(scale=1):
606
+ with gr.Box():
607
+ gr.Markdown("### πŸ“š Memories (Past Interactions)")
608
+ mems_disp_json = gr.JSON(label="View Memories (JSON format)", scale=2)
609
+ with gr.Row(): view_mems_btn = gr.Button("πŸ”„ Load/Refresh Memories View")
610
+ upload_mems_fobj = gr.File(label="Upload Memories File (.jsonl)", file_types=[".jsonl"])
611
+ mems_stat_tb = gr.Textbox(label="Memories Operation Status", interactive=False, lines=2, placeholder="Status of memory operations...")
612
+ clear_mems_btn = gr.Button("⚠️ Clear All Memories", variant="stop")
613
 
614
+ # --- Event Handlers (remain the same as your last correct version) ---
615
  def dyn_upd_model_dd(sel_prov_dyn:str): models_dyn, def_model_dyn = get_model_display_names_for_provider(sel_prov_dyn), get_default_model_display_name_for_provider(sel_prov_dyn); return gr.Dropdown(choices=models_dyn, value=def_model_dyn, interactive=True)
616
  prov_sel_dd.change(fn=dyn_upd_model_dd, inputs=prov_sel_dd, outputs=model_sel_dd)
617
  chat_ins = [user_msg_tb, main_chat_disp, prov_sel_dd, model_sel_dd, api_key_tb, sys_prompt_tb]
 
657
 
658
  demo.load(fn=app_load_fn, inputs=None, outputs=[agent_stat_tb, rules_disp_ta, mems_disp_json])
659
 
660
+
661
  if __name__ == "__main__":
662
+ logger.info(f"Starting Gradio AI Research Mega Agent (v5.3 with UI fixes & Advanced Memory: {MEMORY_STORAGE_BACKEND})...")
663
  app_port, app_server = int(os.getenv("GRADIO_PORT", 7860)), os.getenv("GRADIO_SERVER_NAME", "127.0.0.1")
664
  app_debug, app_share = os.getenv("GRADIO_DEBUG", "False").lower()=="true", os.getenv("GRADIO_SHARE", "False").lower()=="true"
665
  logger.info(f"Launching Gradio server: http://{app_server}:{app_port}. Debug: {app_debug}, Share: {app_share}")
666
+ demo.queue().launch(server_name=app_server, server_port=app_port, debug=app_debug, share=app_share) # fill_height might not be needed with body/container min-height
667
  logger.info("Gradio application shut down.")