GuglielmoTor commited on
Commit
aaf319d
·
verified ·
1 Parent(s): d40cdca

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -49
app.py CHANGED
@@ -132,55 +132,28 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue", secondary_hue="sky"),
132
  fn_generate_llm_response=generate_llm_response
133
  )
134
 
135
- # --- MODIFIED: Handler now uses the session cache ---
136
- def update_report_and_okr_display(selected_report_id: str, current_token_state: dict, session_cache: dict):
137
- error_return_tuple = (
138
- gr.update(value="*Please select a report to view its details.*"),
139
- gr.update(choices=[], value=[], interactive=False),
140
- gr.update(value="*Please select a report to see OKRs.*"),
141
- None, [], [], session_cache # Pass cache back unchanged
142
- )
143
  if not selected_report_id:
144
- return error_return_tuple
145
 
146
  agentic_df = current_token_state.get("bubble_agentic_analysis_data")
147
  if agentic_df is None or agentic_df.empty:
148
- return error_return_tuple
149
 
150
  selected_report_series_df = agentic_df[agentic_df['_id'] == selected_report_id]
151
  if selected_report_series_df.empty:
152
- error_return_tuple[0] = gr.update(value=f"*Error: Report with ID {selected_report_id} not found.*")
153
- return error_return_tuple
154
-
155
  selected_report_series = selected_report_series_df.iloc[0]
156
  report_markdown = format_report_for_display(selected_report_series)
157
 
158
- # Use the session cache
159
- reconstructed_data, updated_cache = fetch_and_reconstruct_data_from_bubble(selected_report_series, session_cache)
160
-
161
- if reconstructed_data:
162
- raw_results_state = reconstructed_data
163
- actionable_okrs_dict = reconstructed_data.get("actionable_okrs", {})
164
- all_krs_state = extract_key_results_for_selection(actionable_okrs_dict)
165
- if all_krs_state:
166
- kr_choices = [(kr['kr_description'], kr['unique_kr_id']) for kr in all_krs_state]
167
- key_results_cbg_update = gr.update(choices=kr_choices, value=[], interactive=True)
168
- okrs_list = actionable_okrs_dict.get("okrs", [])
169
- output_md_parts = [format_single_okr_for_display(okr, okr_main_index=i) for i, okr in enumerate(okrs_list)]
170
- okr_details_md = "\n\n---\n\n".join(output_md_parts) if output_md_parts else "No OKRs defined."
171
- else:
172
- key_results_cbg_update = gr.update(choices=[], value=[], interactive=False)
173
- okr_details_md = "No Key Results found for this report."
174
- all_krs_state = []
175
- else:
176
- key_results_cbg_update = gr.update(choices=[], value=[], interactive=False)
177
- okr_details_md = "Error: Could not fetch or reconstruct OKR data."
178
- raw_results_state, all_krs_state = None, []
179
-
180
- return (
181
- report_markdown, key_results_cbg_update, okr_details_md,
182
- raw_results_state, [], all_krs_state, updated_cache
183
- )
184
 
185
  with gr.Tabs() as tabs:
186
  with gr.TabItem("1️⃣ Dashboard", id="tab_dashboard"):
@@ -243,22 +216,19 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue", secondary_hue="sky"),
243
  )
244
 
245
  if AGENTIC_MODULES_LOADED:
246
- report_selection_outputs = [
247
- agentic_report_display_md, key_results_cbg, okr_detail_display_md,
248
- orchestration_raw_results_st, selected_key_result_ids_st,
249
- key_results_for_selection_st, reconstruction_cache_st # Pass cache state back
250
- ]
251
  report_selector_dd.change(
252
- fn=update_report_and_okr_display,
253
- inputs=[report_selector_dd, token_state, reconstruction_cache_st], # Pass cache state in
254
- outputs=report_selection_outputs,
255
  show_progress="minimal"
256
  )
257
 
258
  agentic_display_outputs = [
259
  agentic_report_display_md, report_selector_dd, key_results_cbg,
260
  okr_detail_display_md, orchestration_raw_results_st, selected_key_result_ids_st,
261
- key_results_for_selection_st, agentic_pipeline_status_md, reconstruction_cache_st # Pass cache state back
262
  ]
263
 
264
  initial_load_event = org_urn_display.change(
@@ -276,7 +246,7 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue", secondary_hue="sky"),
276
  show_progress="full"
277
  ).then(
278
  fn=load_and_display_agentic_results,
279
- inputs=[token_state, reconstruction_cache_st], # Pass cache state in
280
  outputs=agentic_display_outputs,
281
  show_progress="minimal"
282
  )
 
132
  fn_generate_llm_response=generate_llm_response
133
  )
134
 
135
+ # --- FIXED: New handler only updates the report display ---
136
+ def update_report_display(selected_report_id: str, current_token_state: dict):
137
+ """
138
+ Updates only the report display markdown when a new report is selected.
139
+ The OKR visualization remains unchanged as it's loaded initially.
140
+ """
 
 
141
  if not selected_report_id:
142
+ return gr.update(value="*Please select a report to view its details.*")
143
 
144
  agentic_df = current_token_state.get("bubble_agentic_analysis_data")
145
  if agentic_df is None or agentic_df.empty:
146
+ return gr.update(value="*Analysis data not loaded or is empty.*")
147
 
148
  selected_report_series_df = agentic_df[agentic_df['_id'] == selected_report_id]
149
  if selected_report_series_df.empty:
150
+ return gr.update(value=f"*Error: Report with ID '{selected_report_id}' not found.*")
151
+
152
+ # Extract the report data and format it for display
153
  selected_report_series = selected_report_series_df.iloc[0]
154
  report_markdown = format_report_for_display(selected_report_series)
155
 
156
+ return report_markdown
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
157
 
158
  with gr.Tabs() as tabs:
159
  with gr.TabItem("1️⃣ Dashboard", id="tab_dashboard"):
 
216
  )
217
 
218
  if AGENTIC_MODULES_LOADED:
219
+ # FIXED: The change event for the report selector now only updates the report display markdown.
220
+ # The OKR visualization is not affected and remains static after the initial load.
 
 
 
221
  report_selector_dd.change(
222
+ fn=update_report_display,
223
+ inputs=[report_selector_dd, token_state],
224
+ outputs=[agentic_report_display_md],
225
  show_progress="minimal"
226
  )
227
 
228
  agentic_display_outputs = [
229
  agentic_report_display_md, report_selector_dd, key_results_cbg,
230
  okr_detail_display_md, orchestration_raw_results_st, selected_key_result_ids_st,
231
+ key_results_for_selection_st, agentic_pipeline_status_md, reconstruction_cache_st
232
  ]
233
 
234
  initial_load_event = org_urn_display.change(
 
246
  show_progress="full"
247
  ).then(
248
  fn=load_and_display_agentic_results,
249
+ inputs=[token_state, reconstruction_cache_st],
250
  outputs=agentic_display_outputs,
251
  show_progress="minimal"
252
  )