GuglielmoTor commited on
Commit
f195bd5
Β·
verified Β·
1 Parent(s): dd307a7

Update ui/ui_main_page_enhancements.py

Browse files
Files changed (1) hide show
  1. ui/ui_main_page_enhancements.py +50 -26
ui/ui_main_page_enhancements.py CHANGED
@@ -1,4 +1,3 @@
1
- #ui_main_page_enhancements.py
2
  import gradio as gr
3
  import pandas as pd # Needed for state variables that hold DataFrames
4
 
@@ -202,7 +201,7 @@ input:focus, textarea:focus, select:focus {
202
  }
203
 
204
  .card:hover {
205
- box-shadow: var(--shadow-medium);
206
  transform: translateY(-2px);
207
  }
208
 
@@ -522,8 +521,14 @@ def update_report_display_enhanced(selected_report_id: str, current_token_state:
522
  )
523
 
524
  def build_main_app_ui(
525
- analytics_tab_instance,
526
- AGENTIC_MODULES_LOADED,
 
 
 
 
 
 
527
  build_home_tab_ui_func,
528
  create_enhanced_report_tab_func,
529
  create_enhanced_okr_tab_func,
@@ -533,12 +538,8 @@ def build_main_app_ui(
533
  Builds the main Gradio application UI with enhanced styling and structure.
534
 
535
  Args:
536
- analytics_tab_instance (AnalyticsTab): An instance of the AnalyticsTab class.
537
- AGENTIC_MODULES_LOADED (bool): Flag indicating if agentic modules are loaded.
538
- build_home_tab_ui_func (callable): Function to build the Home tab UI.
539
- create_enhanced_report_tab_func (callable): Function to create the enhanced Report tab.
540
- create_enhanced_okr_tab_func (callable): Function to create the enhanced OKR tab.
541
- format_report_for_display_func (callable): Function to format report data for display.
542
 
543
  Returns:
544
  tuple: A tuple containing:
@@ -622,6 +623,25 @@ def build_main_app_ui(
622
  )
623
  gr.HTML('</div>')
624
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
625
  with gr.Tabs(elem_classes=["tab-nav"]) as tabs:
626
  # --- HOME TAB ---
627
  with gr.TabItem("🏠 Home", id="tab_home", elem_classes=["tabitem"]):
@@ -638,13 +658,13 @@ def build_main_app_ui(
638
  analytics_tab_instance.create_tab_ui() # This is the "Graphs" tab, assuming its ID is "tab_analytics_module"
639
 
640
  # --- AGENTIC ANALYSIS REPORT TAB ---
641
- with gr.TabItem("πŸ“Š Analysis Reports", id="tab_agentic_report", visible=AGENTIC_MODULES_LOADED, elem_classes=["tabitem"]):
642
  # The create_enhanced_report_tab function handles the CSS and HTML structure
643
  agentic_pipeline_status_md, report_selector_dd, report_header_html_display, report_body_markdown_display = \
644
- create_enhanced_report_tab_func(AGENTIC_MODULES_LOADED)
645
 
646
  # --- AGENTIC OKRS TAB ---
647
- with gr.TabItem("🎯 OKRs & Tasks", id="tab_agentic_okrs", visible=AGENTIC_MODULES_LOADED, elem_classes=["tabitem"]):
648
  gr.HTML("""
649
  <div class="card">
650
  <div class="card-header">
@@ -656,7 +676,9 @@ def build_main_app_ui(
656
  </div>
657
  """)
658
 
659
- if not AGENTIC_MODULES_LOADED:
 
 
660
  gr.HTML("""
661
  <div class="card" style="text-align: center; padding: 2rem;">
662
  <div style="font-size: 2rem; margin-bottom: 1rem;">πŸ”΄</div>
@@ -664,16 +686,16 @@ def build_main_app_ui(
664
  <p>Agentic modules could not be loaded. This tab is currently unavailable.</p>
665
  </div>
666
  """)
 
 
 
 
 
 
 
667
 
668
- # Keep the old components but make them invisible to maintain load_and_display_agentic_results signature
669
- with gr.Column(visible=False):
670
- gr.Markdown("### Suggested Key Results (OLD UI - HIDDEN)")
671
- key_results_cbg = gr.CheckboxGroup(label="Select Key Results", choices=[], value=[], interactive=True)
672
- gr.Markdown("### Detailed OKRs and Tasks (OLD UI - HIDDEN)")
673
- okr_detail_display_md = gr.Markdown("I dettagli OKR appariranno qui.")
674
-
675
- # NEW: Add the enhanced OKR display HTML component
676
- enhanced_okr_display_html = create_enhanced_okr_tab_func()
677
 
678
  # Add footer with enhanced styling
679
  gr.HTML("""
@@ -687,18 +709,19 @@ def build_main_app_ui(
687
 
688
  # Ensure agentic_display_outputs correctly maps to the newly created components
689
  # This list must match the outputs of load_and_display_agentic_results
 
690
  agentic_display_outputs = [
691
  agentic_pipeline_status_md, # 0: Status Markdown (hidden)
692
  report_selector_dd, # 1: Dropdown for selecting reports
693
- key_results_cbg, # 2: Checkbox group for OKRs (kept hidden)
694
- okr_detail_display_md, # 3: Markdown for detailed OKR display (kept hidden)
695
  orchestration_raw_results_st, # 4: Raw results state
696
  selected_key_result_ids_st, # 5: Selected KR IDs state (kept hidden)
697
  key_results_for_selection_st, # 6: All KRs for selection state (kept hidden)
698
  report_header_html_display, # 7: New HTML output for header
699
  report_body_markdown_display, # 8: New Markdown output for body
700
  reconstruction_cache_st, # 9: Reconstruction cache state
701
- enhanced_okr_display_html, # 10: NEW: The enhanced HTML display for OKRs
702
  actionable_okrs_data_st # 11: NEW: The actionable_okrs dictionary state
703
  ]
704
 
@@ -706,4 +729,5 @@ def build_main_app_ui(
706
  token_state, reconstruction_cache_st, enhanced_okr_display_html,
707
  tabs, report_selector_dd, agentic_display_outputs,
708
  analytics_tab_instance, chat_histories_st,
 
709
  format_report_for_display_func) # Return format_report_for_display_func as well
 
 
1
  import gradio as gr
2
  import pandas as pd # Needed for state variables that hold DataFrames
3
 
 
201
  }
202
 
203
  .card:hover {
204
+ box_shadow: var(--shadow-medium);
205
  transform: translateY(-2px);
206
  }
207
 
 
521
  )
522
 
523
  def build_main_app_ui(
524
+ PLOT_ID_TO_FORMULA_KEY_MAP,
525
+ PLOT_FORMULAS,
526
+ BOMB_ICON, EXPLORE_ICON, FORMULA_ICON, ACTIVE_ICON,
527
+ build_analytics_tab_plot_area_func,
528
+ update_analytics_plots_figures_func,
529
+ create_placeholder_plot_func,
530
+ get_initial_insight_prompt_and_suggestions_func,
531
+ generate_llm_response_func,
532
  build_home_tab_ui_func,
533
  create_enhanced_report_tab_func,
534
  create_enhanced_okr_tab_func,
 
538
  Builds the main Gradio application UI with enhanced styling and structure.
539
 
540
  Args:
541
+ (All necessary functions and constants are passed as arguments to ensure self-containment
542
+ within the UI module without direct imports of non-UI related logic)
 
 
 
 
543
 
544
  Returns:
545
  tuple: A tuple containing:
 
623
  )
624
  gr.HTML('</div>')
625
 
626
+ # Instantiate AnalyticsTab here, after all its required gr.State components are defined
627
+ from services.analytics_tab_module import AnalyticsTab # Local import to ensure it's loaded within context
628
+
629
+ analytics_icons = {'bomb': BOMB_ICON, 'explore': EXPLORE_ICON, 'formula': FORMULA_ICON, 'active': ACTIVE_ICON}
630
+ analytics_tab_instance = AnalyticsTab(
631
+ token_state=token_state,
632
+ chat_histories_st=chat_histories_st,
633
+ current_chat_plot_id_st=current_chat_plot_id_st,
634
+ plot_data_for_chatbot_st=plot_data_for_chatbot_st,
635
+ plot_id_to_formula_map=PLOT_ID_TO_FORMULA_KEY_MAP,
636
+ plot_formulas_data=PLOT_FORMULAS,
637
+ icons=analytics_icons,
638
+ fn_build_plot_area=build_analytics_tab_plot_area_func,
639
+ fn_update_plot_figures=update_analytics_plots_figures_func,
640
+ fn_create_placeholder_plot=create_placeholder_plot_func,
641
+ fn_get_initial_insight=get_initial_insight_prompt_and_suggestions_func,
642
+ fn_generate_llm_response=generate_llm_response_func
643
+ )
644
+
645
  with gr.Tabs(elem_classes=["tab-nav"]) as tabs:
646
  # --- HOME TAB ---
647
  with gr.TabItem("🏠 Home", id="tab_home", elem_classes=["tabitem"]):
 
658
  analytics_tab_instance.create_tab_ui() # This is the "Graphs" tab, assuming its ID is "tab_analytics_module"
659
 
660
  # --- AGENTIC ANALYSIS REPORT TAB ---
661
+ with gr.TabItem("πŸ“Š Analysis Reports", id="tab_agentic_report", visible=True, elem_classes=["tabitem"]): # Set visible to True to allow `create_enhanced_report_tab_func` to return components
662
  # The create_enhanced_report_tab function handles the CSS and HTML structure
663
  agentic_pipeline_status_md, report_selector_dd, report_header_html_display, report_body_markdown_display = \
664
+ create_enhanced_report_tab_func(True) # Pass True to create elements
665
 
666
  # --- AGENTIC OKRS TAB ---
667
+ with gr.TabItem("🎯 OKRs & Tasks", id="tab_agentic_okrs", visible=True, elem_classes=["tabitem"]): # Set visible to True to allow components to be created
668
  gr.HTML("""
669
  <div class="card">
670
  <div class="card-header">
 
676
  </div>
677
  """)
678
 
679
+ # The `AGENTIC_MODULES_LOADED` check should control visibility from app.py, not prevent creation here
680
+ # to avoid NoneType errors during UI building.
681
+ if not AGENTIC_MODULES_LOADED: # This check is for conditional display, not creation
682
  gr.HTML("""
683
  <div class="card" style="text-align: center; padding: 2rem;">
684
  <div style="font-size: 2rem; margin-bottom: 1rem;">πŸ”΄</div>
 
686
  <p>Agentic modules could not be loaded. This tab is currently unavailable.</p>
687
  </div>
688
  """)
689
+ else:
690
+ # Keep the old components but make them invisible to maintain load_and_display_agentic_results signature
691
+ with gr.Column(visible=False):
692
+ gr.Markdown("### Suggested Key Results (OLD UI - HIDDEN)")
693
+ key_results_cbg = gr.CheckboxGroup(label="Select Key Results", choices=[], value=[], interactive=True)
694
+ gr.Markdown("### Detailed OKRs and Tasks (OLD UI - HIDDEN)")
695
+ okr_detail_display_md = gr.Markdown("I dettagli OKR appariranno qui.")
696
 
697
+ # NEW: Add the enhanced OKR display HTML component
698
+ enhanced_okr_display_html = create_enhanced_okr_tab_func()
 
 
 
 
 
 
 
699
 
700
  # Add footer with enhanced styling
701
  gr.HTML("""
 
709
 
710
  # Ensure agentic_display_outputs correctly maps to the newly created components
711
  # This list must match the outputs of load_and_display_agentic_results
712
+ # These variables are now defined within the `with app:` block
713
  agentic_display_outputs = [
714
  agentic_pipeline_status_md, # 0: Status Markdown (hidden)
715
  report_selector_dd, # 1: Dropdown for selecting reports
716
+ key_results_cbg if AGENTIC_MODULES_LOADED else gr.State([]), # Ensure it's a component or dummy state
717
+ okr_detail_display_md if AGENTIC_MODULES_LOADED else gr.State(None), # Ensure it's a component or dummy state
718
  orchestration_raw_results_st, # 4: Raw results state
719
  selected_key_result_ids_st, # 5: Selected KR IDs state (kept hidden)
720
  key_results_for_selection_st, # 6: All KRs for selection state (kept hidden)
721
  report_header_html_display, # 7: New HTML output for header
722
  report_body_markdown_display, # 8: New Markdown output for body
723
  reconstruction_cache_st, # 9: Reconstruction cache state
724
+ enhanced_okr_display_html if AGENTIC_MODULES_LOADED else gr.State(get_initial_okr_display()), # NEW: The enhanced HTML display for OKRs
725
  actionable_okrs_data_st # 11: NEW: The actionable_okrs dictionary state
726
  ]
727
 
 
729
  token_state, reconstruction_cache_st, enhanced_okr_display_html,
730
  tabs, report_selector_dd, agentic_display_outputs,
731
  analytics_tab_instance, chat_histories_st,
732
+ current_chat_plot_id_st, plot_data_for_chatbot_st, # Return these as well
733
  format_report_for_display_func) # Return format_report_for_display_func as well