Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -22,6 +22,7 @@ from services.state_manager import load_data_from_bubble
|
|
22 |
from ui.ui_generators import (
|
23 |
build_analytics_tab_plot_area,
|
24 |
build_home_tab_ui, # NEW: Import the function to build the Home tab UI
|
|
|
25 |
BOMB_ICON, EXPLORE_ICON, FORMULA_ICON, ACTIVE_ICON
|
26 |
)
|
27 |
from ui.analytics_plot_generator import update_analytics_plots_figures, create_placeholder_plot
|
@@ -39,7 +40,7 @@ try:
|
|
39 |
from services.report_data_handler import fetch_and_reconstruct_data_from_bubble
|
40 |
# UI formatting functions
|
41 |
from ui.insights_ui_generator import (
|
42 |
-
format_report_for_display,
|
43 |
extract_key_results_for_selection,
|
44 |
format_single_okr_for_display
|
45 |
)
|
@@ -49,7 +50,8 @@ except ImportError as e:
|
|
49 |
AGENTIC_MODULES_LOADED = False
|
50 |
# Placeholder functions to prevent app from crashing if imports fail
|
51 |
def load_and_display_agentic_results(*args, **kwargs):
|
52 |
-
|
|
|
53 |
def fetch_and_reconstruct_data_from_bubble(*args, **kwargs):
|
54 |
return None, {}
|
55 |
def format_report_for_display(report_data):
|
@@ -76,7 +78,7 @@ else:
|
|
76 |
|
77 |
|
78 |
with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue", secondary_hue="sky"),
|
79 |
-
|
80 |
# --- STATE MANAGEMENT ---
|
81 |
token_state = gr.State(value={
|
82 |
"token": None, "client_id": None, "org_urn": None,
|
@@ -138,24 +140,53 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue", secondary_hue="sky"),
|
|
138 |
def update_report_display(selected_report_id: str, current_token_state: dict):
|
139 |
"""
|
140 |
Updates only the report display markdown when a new report is selected.
|
141 |
-
|
142 |
"""
|
143 |
if not selected_report_id:
|
144 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
145 |
|
146 |
agentic_df = current_token_state.get("bubble_agentic_analysis_data")
|
147 |
if agentic_df is None or agentic_df.empty:
|
148 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
149 |
|
150 |
selected_report_series_df = agentic_df[agentic_df['_id'] == selected_report_id]
|
151 |
if selected_report_series_df.empty:
|
152 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
153 |
|
154 |
selected_report_series = selected_report_series_df.iloc[0]
|
|
|
155 |
report_markdown = format_report_for_display(selected_report_series)
|
156 |
|
157 |
return report_markdown
|
158 |
|
|
|
159 |
with gr.Tabs() as tabs:
|
160 |
# --- NEW HOME TAB ---
|
161 |
with gr.TabItem("1️⃣ Home", id="tab_home"):
|
@@ -171,15 +202,14 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue", secondary_hue="sky"),
|
|
171 |
|
172 |
analytics_tab_instance.create_tab_ui() # This is the "Graphs" tab, assuming its ID is "tab_analytics"
|
173 |
|
|
|
|
|
|
|
174 |
with gr.TabItem("3️⃣ Agentic Analysis Report", id="tab_agentic_report", visible=AGENTIC_MODULES_LOADED):
|
175 |
-
|
176 |
-
agentic_pipeline_status_md
|
177 |
-
|
178 |
-
|
179 |
-
report_selector_dd = gr.Dropdown(label="Report Library", choices=[], interactive=True, info="Select a report.")
|
180 |
-
agentic_report_display_md = gr.Markdown("Please select a report from the library to view it.")
|
181 |
-
if not AGENTIC_MODULES_LOADED:
|
182 |
-
gr.Markdown("🔴 **Error:** Agentic modules could not be loaded.")
|
183 |
|
184 |
with gr.TabItem("4️⃣ Agentic OKRs & Tasks", id="tab_agentic_okrs", visible=AGENTIC_MODULES_LOADED):
|
185 |
gr.Markdown("## 🎯 AI Generated OKRs and Actionable Tasks (from Bubble.io)")
|
@@ -226,16 +256,23 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue", secondary_hue="sky"),
|
|
226 |
|
227 |
if AGENTIC_MODULES_LOADED:
|
228 |
report_selector_dd.change(
|
229 |
-
fn=update_report_display,
|
230 |
inputs=[report_selector_dd, token_state],
|
231 |
outputs=[agentic_report_display_md],
|
232 |
show_progress="minimal"
|
233 |
)
|
234 |
|
|
|
235 |
agentic_display_outputs = [
|
236 |
-
agentic_report_display_md,
|
237 |
-
|
238 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
239 |
]
|
240 |
|
241 |
initial_load_event = org_urn_display.change(
|
@@ -269,3 +306,4 @@ if __name__ == "__main__":
|
|
269 |
logging.warning("WARNING: 'GEMINI_API_KEY' is not set.")
|
270 |
|
271 |
app.launch(server_name="0.0.0.0", server_port=int(os.environ.get("PORT", 7860)), debug=True)
|
|
|
|
22 |
from ui.ui_generators import (
|
23 |
build_analytics_tab_plot_area,
|
24 |
build_home_tab_ui, # NEW: Import the function to build the Home tab UI
|
25 |
+
create_enhanced_report_tab, # NEW: Import the function to build the enhanced Report tab UI
|
26 |
BOMB_ICON, EXPLORE_ICON, FORMULA_ICON, ACTIVE_ICON
|
27 |
)
|
28 |
from ui.analytics_plot_generator import update_analytics_plots_figures, create_placeholder_plot
|
|
|
40 |
from services.report_data_handler import fetch_and_reconstruct_data_from_bubble
|
41 |
# UI formatting functions
|
42 |
from ui.insights_ui_generator import (
|
43 |
+
format_report_for_display, # This will now be the enhanced version
|
44 |
extract_key_results_for_selection,
|
45 |
format_single_okr_for_display
|
46 |
)
|
|
|
50 |
AGENTIC_MODULES_LOADED = False
|
51 |
# Placeholder functions to prevent app from crashing if imports fail
|
52 |
def load_and_display_agentic_results(*args, **kwargs):
|
53 |
+
# NOTE: This return signature MUST match agentic_display_outputs
|
54 |
+
return gr.update(value="Modules not loaded."), gr.update(choices=[], value=None), gr.update(choices=[], value=[], value=[]), gr.update(value="Modules not loaded."), None, [], [], "Error", {}
|
55 |
def fetch_and_reconstruct_data_from_bubble(*args, **kwargs):
|
56 |
return None, {}
|
57 |
def format_report_for_display(report_data):
|
|
|
78 |
|
79 |
|
80 |
with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue", secondary_hue="sky"),
|
81 |
+
title="LinkedIn Organization Dashboard") as app:
|
82 |
# --- STATE MANAGEMENT ---
|
83 |
token_state = gr.State(value={
|
84 |
"token": None, "client_id": None, "org_urn": None,
|
|
|
140 |
def update_report_display(selected_report_id: str, current_token_state: dict):
|
141 |
"""
|
142 |
Updates only the report display markdown when a new report is selected.
|
143 |
+
This function now uses the enhanced formatting from ui/insights_ui_generator.py.
|
144 |
"""
|
145 |
if not selected_report_id:
|
146 |
+
# Return an empty state HTML for no selection
|
147 |
+
return gr.update(value="""
|
148 |
+
<div class="empty-state">
|
149 |
+
<div class="empty-state-icon">📋</div>
|
150 |
+
<div class="empty-state-title">Select a Report</div>
|
151 |
+
<div class="empty-state-description">
|
152 |
+
Choose a report from the dropdown above to view its detailed analysis and insights.
|
153 |
+
</div>
|
154 |
+
</div>
|
155 |
+
""")
|
156 |
|
157 |
agentic_df = current_token_state.get("bubble_agentic_analysis_data")
|
158 |
if agentic_df is None or agentic_df.empty:
|
159 |
+
# Return an empty state HTML for no data
|
160 |
+
return gr.update(value="""
|
161 |
+
<div class="empty-state">
|
162 |
+
<div class="empty-state-icon">⚠️</div>
|
163 |
+
<div class="empty-state-title">Data Not Available</div>
|
164 |
+
<div class="empty-state-description">
|
165 |
+
Analysis data is not loaded or is empty. Please try refreshing the page.
|
166 |
+
</div>
|
167 |
+
</div>
|
168 |
+
""")
|
169 |
|
170 |
selected_report_series_df = agentic_df[agentic_df['_id'] == selected_report_id]
|
171 |
if selected_report_series_df.empty:
|
172 |
+
# Return an empty state HTML for report not found
|
173 |
+
return gr.update(value=f"""
|
174 |
+
<div class="empty-state">
|
175 |
+
<div class="empty-state-icon">❌</div>
|
176 |
+
<div class="empty-state-title">Report Not Found</div>
|
177 |
+
<div class="empty-state-description">
|
178 |
+
Report with ID '{selected_report_id}' was not found in the database.
|
179 |
+
</div>
|
180 |
+
</div>
|
181 |
+
""")
|
182 |
|
183 |
selected_report_series = selected_report_series_df.iloc[0]
|
184 |
+
# Call the now-enhanced format_report_for_display from ui/insights_ui_generator.py
|
185 |
report_markdown = format_report_for_display(selected_report_series)
|
186 |
|
187 |
return report_markdown
|
188 |
|
189 |
+
|
190 |
with gr.Tabs() as tabs:
|
191 |
# --- NEW HOME TAB ---
|
192 |
with gr.TabItem("1️⃣ Home", id="tab_home"):
|
|
|
202 |
|
203 |
analytics_tab_instance.create_tab_ui() # This is the "Graphs" tab, assuming its ID is "tab_analytics"
|
204 |
|
205 |
+
# --- REPLACED: Agentic Analysis Report Tab with enhanced UI ---
|
206 |
+
# The create_enhanced_report_tab function now builds this entire tab's UI.
|
207 |
+
# It also returns the relevant Gradio components needed for callbacks.
|
208 |
with gr.TabItem("3️⃣ Agentic Analysis Report", id="tab_agentic_report", visible=AGENTIC_MODULES_LOADED):
|
209 |
+
# The create_enhanced_report_tab function handles the CSS and HTML structure
|
210 |
+
agentic_pipeline_status_md, report_selector_dd, agentic_report_display_md = \
|
211 |
+
create_enhanced_report_tab(AGENTIC_MODULES_LOADED)
|
212 |
+
|
|
|
|
|
|
|
|
|
213 |
|
214 |
with gr.TabItem("4️⃣ Agentic OKRs & Tasks", id="tab_agentic_okrs", visible=AGENTIC_MODULES_LOADED):
|
215 |
gr.Markdown("## 🎯 AI Generated OKRs and Actionable Tasks (from Bubble.io)")
|
|
|
256 |
|
257 |
if AGENTIC_MODULES_LOADED:
|
258 |
report_selector_dd.change(
|
259 |
+
fn=update_report_display, # This now calls the enhanced function
|
260 |
inputs=[report_selector_dd, token_state],
|
261 |
outputs=[agentic_report_display_md],
|
262 |
show_progress="minimal"
|
263 |
)
|
264 |
|
265 |
+
# Ensure agentic_display_outputs correctly maps to the newly created components
|
266 |
agentic_display_outputs = [
|
267 |
+
agentic_report_display_md, # Updated by create_enhanced_report_tab
|
268 |
+
report_selector_dd, # Updated by create_enhanced_report_tab
|
269 |
+
key_results_cbg,
|
270 |
+
okr_detail_display_md,
|
271 |
+
orchestration_raw_results_st,
|
272 |
+
selected_key_result_ids_st,
|
273 |
+
key_results_for_selection_st,
|
274 |
+
agentic_pipeline_status_md, # Updated by create_enhanced_report_tab
|
275 |
+
reconstruction_cache_st
|
276 |
]
|
277 |
|
278 |
initial_load_event = org_urn_display.change(
|
|
|
306 |
logging.warning("WARNING: 'GEMINI_API_KEY' is not set.")
|
307 |
|
308 |
app.launch(server_name="0.0.0.0", server_port=int(os.environ.get("PORT", 7860)), debug=True)
|
309 |
+
|