GuglielmoTor commited on
Commit
94b5f2a
·
verified ·
1 Parent(s): 091b257

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -108
app.py CHANGED
@@ -37,7 +37,7 @@ from features.chatbot.chatbot_handler import generate_llm_response # Pass this
37
 
38
  # --- NEW AGENTIC PIPELINE IMPORTS ---
39
  try:
40
- from run_agentic_pipeline import run_full_analytics_orchestration
41
  from ui.insights_ui_generator import (
42
  format_report_to_markdown,
43
  extract_key_results_for_selection,
@@ -212,113 +212,6 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue", secondary_hue="sky"),
212
  api_name="update_okr_display_on_selection_module"
213
  )
214
 
215
- async def run_agentic_pipeline_autonomously(current_token_state_val):
216
- logging.info(f"Agentic pipeline check triggered for token_state update. Current token: {'Set' if current_token_state_val.get('token') else 'Not Set'}")
217
- # Initial state before pipeline runs or if skipped
218
- initial_yield = (
219
- gr.update(value="Pipeline AI: In attesa dei dati necessari..."), # agentic_report_display_md
220
- gr.update(choices=[], value=[], interactive=False), # key_results_cbg
221
- gr.update(value="Pipeline AI: In attesa dei dati necessari..."), # okr_detail_display_md
222
- orchestration_raw_results_st.value, # Preserve current raw results
223
- selected_key_result_ids_st.value, # Preserve current selection
224
- key_results_for_selection_st.value, # Preserve current options
225
- "Pipeline AI: In attesa dei dati..." # agentic_pipeline_status_md
226
- )
227
-
228
- if not current_token_state_val or not current_token_state_val.get("token"):
229
- logging.info("Agentic pipeline: Token not available in token_state. Skipping.")
230
- yield initial_yield
231
- return
232
-
233
- logging.info("Agentic pipeline starting autonomously with 'Sempre' filter.")
234
- # Update status to indicate processing
235
- yield (
236
- gr.update(value="Analisi AI (Sempre) in corso..."),
237
- gr.update(choices=[], value=[], interactive=False), # Keep CBG disabled during run
238
- gr.update(value="Dettagli OKR (Sempre) in corso di generazione..."),
239
- orchestration_raw_results_st.value, # Preserve
240
- selected_key_result_ids_st.value, # Preserve
241
- key_results_for_selection_st.value, # Preserve
242
- "Esecuzione pipeline AI (Sempre)..."
243
- )
244
-
245
- if not AGENTIC_MODULES_LOADED:
246
- logging.warning("Agentic modules not loaded. Skipping autonomous pipeline.")
247
- yield (
248
- gr.update(value="Moduli AI non caricati. Report non disponibile."),
249
- gr.update(choices=[], value=[], interactive=False),
250
- gr.update(value="Moduli AI non caricati. OKR non disponibili."),
251
- None, [], [], "Pipeline AI: Moduli non caricati."
252
- )
253
- return
254
-
255
- try:
256
- # Parameters for 'Sempre' filter for the agentic pipeline
257
- date_filter_val_agentic = "Sempre"
258
- custom_start_val_agentic = None
259
- custom_end_val_agentic = None
260
-
261
- orchestration_output = await run_full_analytics_orchestration(
262
- current_token_state_val,
263
- date_filter_val_agentic,
264
- custom_start_val_agentic,
265
- custom_end_val_agentic
266
- )
267
- agentic_status_text = "Pipeline AI (Sempre) completata."
268
- logging.info(f"Autonomous agentic pipeline finished. Output keys: {orchestration_output.keys() if orchestration_output else 'None'}")
269
-
270
- if orchestration_output:
271
- orchestration_results_update = orchestration_output # Store full results in state
272
- report_str = orchestration_output.get('comprehensive_analysis_report', "Nessun report dettagliato fornito.")
273
- agentic_report_md_update = gr.update(value=format_report_to_markdown(report_str))
274
-
275
- actionable_okrs = orchestration_output.get('actionable_okrs_and_tasks') # This is the dict containing 'okrs' list
276
- krs_for_ui_selection_list = extract_key_results_for_selection(actionable_okrs) # Expects the dict
277
-
278
- krs_for_selection_update = krs_for_ui_selection_list # Update state with list of KR dicts
279
-
280
- # Choices for CheckboxGroup: list of (label, value) tuples
281
- kr_choices_for_cbg = [(kr['kr_description'], kr['unique_kr_id']) for kr in krs_for_ui_selection_list]
282
- key_results_cbg_update = gr.update(choices=kr_choices_for_cbg, value=[], interactive=True) # Reset selection
283
-
284
- # Display all OKRs by default after pipeline run
285
- all_okrs_md_parts = []
286
- if actionable_okrs and isinstance(actionable_okrs.get("okrs"), list):
287
- for okr_idx, okr_item in enumerate(actionable_okrs["okrs"]):
288
- all_okrs_md_parts.append(format_single_okr_for_display(okr_item, accepted_kr_indices=None, okr_main_index=okr_idx))
289
-
290
- if not all_okrs_md_parts:
291
- okr_detail_display_md_update = gr.update(value="Nessun OKR generato o trovato (Sempre).")
292
- else:
293
- okr_detail_display_md_update = gr.update(value="\n\n---\n\n".join(all_okrs_md_parts))
294
-
295
- selected_krs_update = [] # Reset selected KRs state
296
- else:
297
- agentic_report_md_update = gr.update(value="Nessun report generato dalla pipeline AI (Sempre).")
298
- key_results_cbg_update = gr.update(choices=[], value=[], interactive=False)
299
- okr_detail_display_md_update = gr.update(value="Nessun OKR generato o errore nella pipeline AI (Sempre).")
300
- orchestration_results_update = None
301
- selected_krs_update = []
302
- krs_for_selection_update = []
303
-
304
- yield (
305
- agentic_report_md_update,
306
- key_results_cbg_update,
307
- okr_detail_display_md_update,
308
- orchestration_results_update, # state
309
- selected_krs_update, # state
310
- krs_for_selection_update, # state
311
- agentic_status_text
312
- )
313
- except Exception as e:
314
- logging.error(f"Error during autonomous agentic pipeline execution: {e}", exc_info=True)
315
- agentic_status_text = f"Errore pipeline AI (Sempre): {str(e)}"
316
- yield (
317
- gr.update(value=f"Errore generazione report AI (Sempre): {str(e)}"),
318
- gr.update(choices=[], value=[], interactive=False),
319
- gr.update(value=f"Errore generazione OKR AI (Sempre): {str(e)}"),
320
- None, [], [], agentic_status_text # Reset states on error
321
- )
322
 
323
  # Define the output list for the agentic pipeline callbacks
324
  # Order: Report MD, KR CBG, OKR Detail MD, RawResults State, SelectedKRIDs State, KRList State, Status MD
 
37
 
38
  # --- NEW AGENTIC PIPELINE IMPORTS ---
39
  try:
40
+ from run_agentic_pipeline import run_agentic_pipeline_autonomously
41
  from ui.insights_ui_generator import (
42
  format_report_to_markdown,
43
  extract_key_results_for_selection,
 
212
  api_name="update_okr_display_on_selection_module"
213
  )
214
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
215
 
216
  # Define the output list for the agentic pipeline callbacks
217
  # Order: Report MD, KR CBG, OKR Detail MD, RawResults State, SelectedKRIDs State, KRList State, Status MD