GuglielmoTor commited on
Commit
5cc5759
·
verified ·
1 Parent(s): 77b3a80

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +58 -9
app.py CHANGED
@@ -1,4 +1,3 @@
1
- # app.py
2
  import gradio as gr
3
  import pandas as pd
4
  import os
@@ -36,7 +35,8 @@ from features.chatbot.chatbot_handler import generate_llm_response
36
  try:
37
  # UPDATED: Using the new display function to show pre-computed results
38
  from run_agentic_pipeline import load_and_display_agentic_results
39
- from ui.insights_ui_generator import format_single_okr_for_display
 
40
  AGENTIC_MODULES_LOADED = True
41
  except ImportError as e:
42
  logging.error(f"Could not import agentic pipeline display modules: {e}. Tabs 3 and 4 will be disabled.")
@@ -44,9 +44,11 @@ except ImportError as e:
44
  # Placeholder for the new function name if imports fail
45
  def load_and_display_agentic_results(*args, **kwargs):
46
  # This tuple matches the expected number of outputs for the event handler
47
- return "Modules not loaded.", "Modules not loaded.", "Modules not loaded.", None, [], [], "Error"
48
  def format_single_okr_for_display(okr_data, **kwargs):
49
  return "Agentic modules not loaded. OKR display unavailable."
 
 
50
 
51
  # --- ANALYTICS TAB MODULE IMPORT ---
52
  from services.analytics_tab_module import AnalyticsTab
@@ -122,6 +124,30 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue", secondary_hue="sky"),
122
  fn_get_initial_insight=get_initial_insight_prompt_and_suggestions,
123
  fn_generate_llm_response=generate_llm_response
124
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
125
 
126
  with gr.Tabs() as tabs:
127
  with gr.TabItem("1️⃣ Dashboard", id="tab_dashboard"):
@@ -132,12 +158,24 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue", secondary_hue="sky"),
132
  # Use the AnalyticsTab module to create Tab 2
133
  analytics_tab_instance.create_tab_ui()
134
 
135
- # Tab 3: Agentic Analysis Report
136
  with gr.TabItem("3️⃣ Agentic Analysis Report", id="tab_agentic_report", visible=AGENTIC_MODULES_LOADED):
137
  gr.Markdown("## 🤖 Comprehensive Analysis Report (from Bubble.io)")
138
  agentic_pipeline_status_md = gr.Markdown("Status: Loading report data...", visible=True)
139
- gr.Markdown("Questo report è stato pre-generato da un agente AI e caricato da Bubble.io.")
140
- agentic_report_display_md = gr.Markdown("The AI-generated report will be displayed here once loaded.")
 
 
 
 
 
 
 
 
 
 
 
 
141
  if not AGENTIC_MODULES_LOADED:
142
  gr.Markdown("🔴 **Error:** Agentic pipeline display modules could not be loaded. This tab is disabled.")
143
 
@@ -192,11 +230,22 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue", secondary_hue="sky"),
192
  inputs=[key_results_cbg, orchestration_raw_results_st, key_results_for_selection_st],
193
  outputs=[okr_detail_display_md]
194
  )
 
 
 
 
 
 
 
 
 
 
195
 
196
  # --- EVENT HANDLING (SIMPLIFIED) ---
197
- # Define the output list for loading agentic results
198
  agentic_display_outputs = [
199
  agentic_report_display_md,
 
200
  key_results_cbg,
201
  okr_detail_display_md,
202
  orchestration_raw_results_st,
@@ -227,9 +276,9 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue", secondary_hue="sky"),
227
  show_progress="full"
228
  # Then, load and display the pre-computed agentic results
229
  ).then(
230
- fn=load_and_display_agentic_results, # UPDATED function call
231
  inputs=[token_state, orchestration_raw_results_st, selected_key_result_ids_st, key_results_for_selection_st],
232
- outputs=agentic_display_outputs,
233
  show_progress="minimal"
234
  )
235
 
 
 
1
  import gradio as gr
2
  import pandas as pd
3
  import os
 
35
  try:
36
  # UPDATED: Using the new display function to show pre-computed results
37
  from run_agentic_pipeline import load_and_display_agentic_results
38
+ # ADDED: Import the new report formatter
39
+ from ui.insights_ui_generator import format_single_okr_for_display, format_report_for_display
40
  AGENTIC_MODULES_LOADED = True
41
  except ImportError as e:
42
  logging.error(f"Could not import agentic pipeline display modules: {e}. Tabs 3 and 4 will be disabled.")
 
44
  # Placeholder for the new function name if imports fail
45
  def load_and_display_agentic_results(*args, **kwargs):
46
  # This tuple matches the expected number of outputs for the event handler
47
+ return "Modules not loaded.", gr.update(), "Modules not loaded.", "Modules not loaded.", None, [], [], "Error"
48
  def format_single_okr_for_display(okr_data, **kwargs):
49
  return "Agentic modules not loaded. OKR display unavailable."
50
+ def format_report_for_display(report_data):
51
+ return "Agentic modules not loaded. Report display unavailable."
52
 
53
  # --- ANALYTICS TAB MODULE IMPORT ---
54
  from services.analytics_tab_module import AnalyticsTab
 
124
  fn_get_initial_insight=get_initial_insight_prompt_and_suggestions,
125
  fn_generate_llm_response=generate_llm_response
126
  )
127
+
128
+ # --- NEW: Handler function for report selection ---
129
+ def display_selected_report(selected_report_id: str, current_token_state: dict):
130
+ """
131
+ Finds the selected report in the state and formats it for display.
132
+ """
133
+ if not selected_report_id:
134
+ return gr.update(value="*Please select a report from the library.*")
135
+
136
+ agentic_df = current_token_state.get("bubble_agentic_analysis_data")
137
+ if agentic_df is None or agentic_df.empty:
138
+ return gr.update(value="*Report data not loaded. Cannot display report.*")
139
+
140
+ # The dropdown value is the unique ID of the report (e.g., Bubble _id)
141
+ selected_report_series_df = agentic_df[agentic_df['_id'] == selected_report_id]
142
+
143
+ if selected_report_series_df.empty:
144
+ return gr.update(value=f"*Error: Could not find report with ID {selected_report_id}.*")
145
+
146
+ selected_report_series = selected_report_series_df.iloc[0]
147
+ report_markdown = format_report_for_display(selected_report_series)
148
+
149
+ return gr.update(value=report_markdown)
150
+
151
 
152
  with gr.Tabs() as tabs:
153
  with gr.TabItem("1️⃣ Dashboard", id="tab_dashboard"):
 
158
  # Use the AnalyticsTab module to create Tab 2
159
  analytics_tab_instance.create_tab_ui()
160
 
161
+ # Tab 3: Agentic Analysis Report - MODIFIED
162
  with gr.TabItem("3️⃣ Agentic Analysis Report", id="tab_agentic_report", visible=AGENTIC_MODULES_LOADED):
163
  gr.Markdown("## 🤖 Comprehensive Analysis Report (from Bubble.io)")
164
  agentic_pipeline_status_md = gr.Markdown("Status: Loading report data...", visible=True)
165
+ gr.Markdown("Questo report è stato pre-generato da un agente AI e caricato da Bubble.io. Seleziona un report dalla libreria per visualizzarlo.")
166
+
167
+ # NEW: Report library dropdown
168
+ with gr.Row():
169
+ report_selector_dd = gr.Dropdown(
170
+ label="Report Library",
171
+ choices=[],
172
+ interactive=True,
173
+ info="Select a previously generated report to view its details."
174
+ )
175
+
176
+ # This Markdown component will now display the selected report
177
+ agentic_report_display_md = gr.Markdown("Please select a report from the library to view it.")
178
+
179
  if not AGENTIC_MODULES_LOADED:
180
  gr.Markdown("🔴 **Error:** Agentic pipeline display modules could not be loaded. This tab is disabled.")
181
 
 
230
  inputs=[key_results_cbg, orchestration_raw_results_st, key_results_for_selection_st],
231
  outputs=[okr_detail_display_md]
232
  )
233
+
234
+ # --- NEW: Event binding for the report selector dropdown ---
235
+ if AGENTIC_MODULES_LOADED:
236
+ report_selector_dd.change(
237
+ fn=display_selected_report,
238
+ inputs=[report_selector_dd, token_state],
239
+ outputs=[agentic_report_display_md],
240
+ show_progress="minimal"
241
+ )
242
+
243
 
244
  # --- EVENT HANDLING (SIMPLIFIED) ---
245
+ # MODIFIED: Define the output list for loading agentic results
246
  agentic_display_outputs = [
247
  agentic_report_display_md,
248
+ report_selector_dd, # ADDED: The new dropdown
249
  key_results_cbg,
250
  okr_detail_display_md,
251
  orchestration_raw_results_st,
 
276
  show_progress="full"
277
  # Then, load and display the pre-computed agentic results
278
  ).then(
279
+ fn=load_and_display_agentic_results, # This function's implementation needs to be updated
280
  inputs=[token_state, orchestration_raw_results_st, selected_key_result_ids_st, key_results_for_selection_st],
281
+ outputs=agentic_display_outputs, # The output list is now updated
282
  show_progress="minimal"
283
  )
284