Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -18,7 +18,8 @@ from config import (
|
|
18 |
BUBBLE_API_ENDPOINT_ENV_VAR
|
19 |
)
|
20 |
|
21 |
-
|
|
|
22 |
|
23 |
# UPDATED: Using the new data loading function from the refactored state manager
|
24 |
from services.state_manager import load_data_from_bubble
|
@@ -36,7 +37,7 @@ from ui.analytics_plot_generator import update_analytics_plots_figures, create_p
|
|
36 |
from formulas import PLOT_FORMULAS
|
37 |
|
38 |
# NEW: Import UI enhancements from the new module
|
39 |
-
from ui.
|
40 |
|
41 |
# --- CHATBOT MODULE IMPORTS ---
|
42 |
from features.chatbot.chatbot_prompts import get_initial_insight_prompt_and_suggestions
|
@@ -114,57 +115,28 @@ def initial_data_load_sequence(url_token, org_urn_val, current_state):
|
|
114 |
status_msg = f"🔄 {status_msg}"
|
115 |
return status_msg, new_state
|
116 |
|
117 |
-
# Instantiate AnalyticsTab (needs to be done before building UI if its methods are called)
|
118 |
-
analytics_icons = {'bomb': BOMB_ICON, 'explore': EXPLORE_ICON, 'formula': FORMULA_ICON, 'active': ACTIVE_ICON}
|
119 |
-
analytics_tab_instance = AnalyticsTab(
|
120 |
-
# These states are created within build_main_app_ui, but AnalyticsTab needs references.
|
121 |
-
# We will set them after build_main_app_ui returns them. For now, pass placeholders.
|
122 |
-
token_state=None, # Will be updated after build_main_app_ui
|
123 |
-
chat_histories_st=None, # Will be updated after build_main_app_ui
|
124 |
-
current_chat_plot_id_st=None, # Will be updated after build_main_app_ui
|
125 |
-
plot_data_for_chatbot_st=None, # Will be updated after build_main_app_ui
|
126 |
-
plot_id_to_formula_map=PLOT_ID_TO_FORMULA_KEY_MAP,
|
127 |
-
plot_formulas_data=PLOT_FORMULAS,
|
128 |
-
icons=analytics_icons,
|
129 |
-
fn_build_plot_area=build_analytics_tab_plot_area,
|
130 |
-
fn_update_plot_figures=update_analytics_plots_figures,
|
131 |
-
fn_create_placeholder_plot=create_placeholder_plot,
|
132 |
-
fn_get_initial_insight=get_initial_insight_prompt_and_suggestions,
|
133 |
-
fn_generate_llm_response=generate_llm_response
|
134 |
-
)
|
135 |
-
|
136 |
-
|
137 |
# Build the main UI using the function from ui_enhancements
|
138 |
(app, url_user_token_display, org_urn_display, status_box,
|
139 |
token_state, reconstruction_cache_st, enhanced_okr_display_html,
|
140 |
tabs, report_selector_dd, agentic_display_outputs,
|
141 |
-
|
|
|
|
|
142 |
build_main_app_ui(
|
143 |
-
|
144 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
145 |
build_home_tab_ui_func=build_home_tab_ui,
|
146 |
create_enhanced_report_tab_func=create_enhanced_report_tab,
|
147 |
create_enhanced_okr_tab_func=create_enhanced_okr_tab,
|
148 |
format_report_for_display_func=format_report_for_display # Pass the imported function
|
149 |
)
|
150 |
|
151 |
-
# Now, update the analytics_tab_instance with the actual state components from the built UI
|
152 |
-
# This is crucial because analytics_tab_instance was instantiated before the gr.State components existed.
|
153 |
-
analytics_tab_instance.token_state = token_state
|
154 |
-
analytics_tab_instance.chat_histories_st = chat_histories_st_returned
|
155 |
-
analytics_tab_instance.current_chat_plot_id_st = agentic_display_outputs[9] # This is current_chat_plot_id_st
|
156 |
-
analytics_tab_instance.plot_data_for_chatbot_st = agentic_display_outputs[11] # This is actionable_okrs_data_st, which is incorrect. Should be plot_data_for_chatbot_st
|
157 |
-
|
158 |
-
# Corrected update for analytics_tab_instance state components.
|
159 |
-
# Need to know the exact index of each state in agentic_display_outputs or pass them directly.
|
160 |
-
# Given the `build_main_app_ui` returns specific components, let's use those directly.
|
161 |
-
# The original code for `chat_histories_st`, `current_chat_plot_id_st`, `plot_data_for_chatbot_st`
|
162 |
-
# are defined within `build_main_app_ui`'s scope.
|
163 |
-
# The returned `chat_histories_st_returned` and the other states are the correct references.
|
164 |
-
# So, no need to access them via `agentic_display_outputs` for the analytics_tab_instance.
|
165 |
-
# The parameters `chat_histories_st_returned` (which is `chat_histories_st` inside `build_main_app_ui`)
|
166 |
-
# and others are the correct references.
|
167 |
-
|
168 |
# Event handlers (re-establishing them now that components are defined)
|
169 |
app.load(fn=get_url_user_token, inputs=None, outputs=[url_user_token_display, org_urn_display], api_name="get_url_params", show_progress=False)
|
170 |
|
@@ -186,9 +158,9 @@ initial_load_event = org_urn_display.change(
|
|
186 |
|
187 |
# Chain the loading events
|
188 |
initial_load_event.then(
|
189 |
-
fn=analytics_tab_instance.refresh_analytics_graphs_ui,
|
190 |
inputs=[token_state, analytics_tab_instance.date_filter_selector, analytics_tab_instance.custom_start_date_picker,
|
191 |
-
analytics_tab_instance.custom_end_date_picker, chat_histories_st_returned],
|
192 |
outputs=analytics_tab_instance.graph_refresh_outputs_list,
|
193 |
show_progress="full"
|
194 |
).then(
|
|
|
18 |
BUBBLE_API_ENDPOINT_ENV_VAR
|
19 |
)
|
20 |
|
21 |
+
# analytics_tab_module is now imported locally inside ui/ui_enhancements.py's build_main_app_ui
|
22 |
+
# from services.analytics_tab_module import AnalyticsTab # REMOVED global import here
|
23 |
|
24 |
# UPDATED: Using the new data loading function from the refactored state manager
|
25 |
from services.state_manager import load_data_from_bubble
|
|
|
37 |
from formulas import PLOT_FORMULAS
|
38 |
|
39 |
# NEW: Import UI enhancements from the new module
|
40 |
+
from ui.ui_enhancements import build_main_app_ui, update_report_display_enhanced
|
41 |
|
42 |
# --- CHATBOT MODULE IMPORTS ---
|
43 |
from features.chatbot.chatbot_prompts import get_initial_insight_prompt_and_suggestions
|
|
|
115 |
status_msg = f"🔄 {status_msg}"
|
116 |
return status_msg, new_state
|
117 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
118 |
# Build the main UI using the function from ui_enhancements
|
119 |
(app, url_user_token_display, org_urn_display, status_box,
|
120 |
token_state, reconstruction_cache_st, enhanced_okr_display_html,
|
121 |
tabs, report_selector_dd, agentic_display_outputs,
|
122 |
+
analytics_tab_instance, chat_histories_st_returned,
|
123 |
+
current_chat_plot_id_st_returned, plot_data_for_chatbot_st_returned, # Receive these returned states
|
124 |
+
format_report_for_display_func_passed) = \
|
125 |
build_main_app_ui(
|
126 |
+
PLOT_ID_TO_FORMULA_KEY_MAP=PLOT_ID_TO_FORMULA_KEY_MAP,
|
127 |
+
PLOT_FORMULAS=PLOT_FORMULAS,
|
128 |
+
BOMB_ICON=BOMB_ICON, EXPLORE_ICON=EXPLORE_ICON, FORMULA_ICON=FORMULA_ICON, ACTIVE_ICON=ACTIVE_ICON,
|
129 |
+
build_analytics_tab_plot_area_func=build_analytics_tab_plot_area,
|
130 |
+
update_analytics_plots_figures_func=update_analytics_plots_figures,
|
131 |
+
create_placeholder_plot_func=create_placeholder_plot,
|
132 |
+
get_initial_insight_prompt_and_suggestions_func=get_initial_insight_prompt_and_suggestions,
|
133 |
+
generate_llm_response_func=generate_llm_response,
|
134 |
build_home_tab_ui_func=build_home_tab_ui,
|
135 |
create_enhanced_report_tab_func=create_enhanced_report_tab,
|
136 |
create_enhanced_okr_tab_func=create_enhanced_okr_tab,
|
137 |
format_report_for_display_func=format_report_for_display # Pass the imported function
|
138 |
)
|
139 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
140 |
# Event handlers (re-establishing them now that components are defined)
|
141 |
app.load(fn=get_url_user_token, inputs=None, outputs=[url_user_token_display, org_urn_display], api_name="get_url_params", show_progress=False)
|
142 |
|
|
|
158 |
|
159 |
# Chain the loading events
|
160 |
initial_load_event.then(
|
161 |
+
fn=analytics_tab_instance.refresh_analytics_graphs_ui,
|
162 |
inputs=[token_state, analytics_tab_instance.date_filter_selector, analytics_tab_instance.custom_start_date_picker,
|
163 |
+
analytics_tab_instance.custom_end_date_picker, chat_histories_st_returned],
|
164 |
outputs=analytics_tab_instance.graph_refresh_outputs_list,
|
165 |
show_progress="full"
|
166 |
).then(
|