Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -40,7 +40,7 @@ try:
|
|
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
|
44 |
extract_key_results_for_selection,
|
45 |
format_single_okr_for_display
|
46 |
)
|
@@ -51,11 +51,41 @@ except ImportError as e:
|
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
def fetch_and_reconstruct_data_from_bubble(*args, **kwargs):
|
56 |
return None, {}
|
57 |
def format_report_for_display(report_data):
|
58 |
-
|
|
|
59 |
def extract_key_results_for_selection(okr_data):
|
60 |
return []
|
61 |
def format_single_okr_for_display(okr_data, **kwargs):
|
@@ -139,52 +169,68 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue", secondary_hue="sky"),
|
|
139 |
|
140 |
def update_report_display(selected_report_id: str, current_token_state: dict):
|
141 |
"""
|
142 |
-
Updates
|
143 |
-
This function now
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
144 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
145 |
if not selected_report_id:
|
146 |
-
#
|
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 |
-
#
|
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 |
-
#
|
173 |
-
return gr.update(value=
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
188 |
|
189 |
|
190 |
with gr.Tabs() as tabs:
|
@@ -207,7 +253,8 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue", secondary_hue="sky"),
|
|
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 |
-
|
|
|
211 |
create_enhanced_report_tab(AGENTIC_MODULES_LOADED)
|
212 |
|
213 |
|
@@ -257,22 +304,25 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue", secondary_hue="sky"),
|
|
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=[
|
262 |
show_progress="minimal"
|
263 |
)
|
264 |
|
265 |
# Ensure agentic_display_outputs correctly maps to the newly created components
|
|
|
266 |
agentic_display_outputs = [
|
267 |
-
|
268 |
-
report_selector_dd,
|
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 |
-
|
275 |
-
|
|
|
276 |
]
|
277 |
|
278 |
initial_load_event = org_urn_display.change(
|
@@ -291,6 +341,7 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue", secondary_hue="sky"),
|
|
291 |
).then(
|
292 |
fn=load_and_display_agentic_results,
|
293 |
inputs=[token_state, reconstruction_cache_st],
|
|
|
294 |
outputs=agentic_display_outputs,
|
295 |
show_progress="minimal"
|
296 |
)
|
|
|
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 return header HTML and body Markdown
|
44 |
extract_key_results_for_selection,
|
45 |
format_single_okr_for_display
|
46 |
)
|
|
|
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 |
+
# Adjusted return values for the new split report display components
|
55 |
+
empty_header_html = """
|
56 |
+
<div class="report-title">π Comprehensive Analysis Report</div>
|
57 |
+
<div class="report-subtitle">AI-Generated Insights from Your LinkedIn Data</div>
|
58 |
+
<div class="status-badge">Generated from Bubble.io</div>
|
59 |
+
"""
|
60 |
+
empty_body_markdown = """
|
61 |
+
<div class="empty-state">
|
62 |
+
<div class="empty-state-icon">π</div>
|
63 |
+
<div class="empty-state-title">No Report Selected</div>
|
64 |
+
<div class="empty-state-description">
|
65 |
+
Please select a report from the library above to view its detailed analysis and insights.
|
66 |
+
</div>
|
67 |
+
</div>
|
68 |
+
"""
|
69 |
+
# The load_and_display_agentic_results function returns many values.
|
70 |
+
# Ensure the placeholder returns the correct number of gr.update components
|
71 |
+
# matching the `outputs` in the .then() call later.
|
72 |
+
return (
|
73 |
+
gr.update(value="Modules not loaded."), # agentic_pipeline_status_md
|
74 |
+
gr.update(choices=[], value=None), # report_selector_dd
|
75 |
+
gr.update(choices=[], value=[]), # key_results_cbg
|
76 |
+
gr.update(value="Modules not loaded."), # okr_detail_display_md
|
77 |
+
None, # orchestration_raw_results_st
|
78 |
+
[], # selected_key_result_ids_st
|
79 |
+
[], # key_results_for_selection_st
|
80 |
+
gr.update(value=empty_header_html), # report_header_html_display
|
81 |
+
gr.update(value=empty_body_markdown), # report_body_markdown_display
|
82 |
+
{} # reconstruction_cache_st
|
83 |
+
)
|
84 |
def fetch_and_reconstruct_data_from_bubble(*args, **kwargs):
|
85 |
return None, {}
|
86 |
def format_report_for_display(report_data):
|
87 |
+
# Placeholder for when modules are not loaded, returns structure matching the new design
|
88 |
+
return {'header_html': '<h1>Agentic modules not loaded.</h1>', 'body_markdown': 'Report display unavailable.'}
|
89 |
def extract_key_results_for_selection(okr_data):
|
90 |
return []
|
91 |
def format_single_okr_for_display(okr_data, **kwargs):
|
|
|
169 |
|
170 |
def update_report_display(selected_report_id: str, current_token_state: dict):
|
171 |
"""
|
172 |
+
Updates the report header and body display when a new report is selected.
|
173 |
+
This function now expects format_report_for_display to return a dict with
|
174 |
+
'header_html' and 'body_markdown'.
|
175 |
+
"""
|
176 |
+
# Define empty states for header and body
|
177 |
+
empty_header_html = """
|
178 |
+
<div class="report-title">π Comprehensive Analysis Report</div>
|
179 |
+
<div class="report-subtitle">AI-Generated Insights from Your LinkedIn Data</div>
|
180 |
+
<div class="status-badge">Generated from Bubble.io</div>
|
181 |
+
"""
|
182 |
+
empty_body_markdown_no_selection = """
|
183 |
+
<div class="empty-state">
|
184 |
+
<div class="empty-state-icon">π</div>
|
185 |
+
<div class="empty-state-title">Select a Report</div>
|
186 |
+
<div class="empty-state-description">
|
187 |
+
Choose a report from the dropdown above to view its detailed analysis and insights.
|
188 |
+
</div>
|
189 |
+
</div>
|
190 |
"""
|
191 |
+
empty_body_markdown_no_data = """
|
192 |
+
<div class="empty-state">
|
193 |
+
<div class="empty-state-icon">β οΈ</div>
|
194 |
+
<div class="empty-state-title">Data Not Available</div>
|
195 |
+
<div class="empty-state-description">
|
196 |
+
Analysis data is not loaded or is empty. Please try refreshing the page.
|
197 |
+
</div>
|
198 |
+
</div>
|
199 |
+
"""
|
200 |
+
empty_body_markdown_not_found = lambda _id: f"""
|
201 |
+
<div class="empty-state">
|
202 |
+
<div class="empty-state-icon">β</div>
|
203 |
+
<div class="empty-state-title">Report Not Found</div>
|
204 |
+
<div class="empty-state-description">
|
205 |
+
Report with ID '{_id}' was not found in the database.
|
206 |
+
</div>
|
207 |
+
</div>
|
208 |
+
"""
|
209 |
+
|
210 |
if not selected_report_id:
|
211 |
+
# When no report is selected, update both header and body
|
212 |
+
return gr.update(value=empty_header_html), gr.update(value=empty_body_markdown_no_selection)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
213 |
|
214 |
agentic_df = current_token_state.get("bubble_agentic_analysis_data")
|
215 |
if agentic_df is None or agentic_df.empty:
|
216 |
+
# When no data is available, update both header and body
|
217 |
+
return gr.update(value=empty_header_html), gr.update(value=empty_body_markdown_no_data)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
218 |
|
219 |
selected_report_series_df = agentic_df[agentic_df['_id'] == selected_report_id]
|
220 |
if selected_report_series_df.empty:
|
221 |
+
# When report is not found, update both header and body
|
222 |
+
return gr.update(value=empty_header_html), gr.update(value=empty_body_markdown_not_found(selected_report_id))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
223 |
|
224 |
selected_report_series = selected_report_series_df.iloc[0]
|
|
|
|
|
225 |
|
226 |
+
# Call the format_report_for_display, which now returns a dict
|
227 |
+
formatted_content_parts = format_report_for_display(selected_report_series)
|
228 |
+
|
229 |
+
# Update the two separate Gradio components
|
230 |
+
return (
|
231 |
+
gr.update(value=formatted_content_parts['header_html']),
|
232 |
+
gr.update(value=formatted_content_parts['body_markdown'])
|
233 |
+
)
|
234 |
|
235 |
|
236 |
with gr.Tabs() as tabs:
|
|
|
253 |
# It also returns the relevant Gradio components needed for callbacks.
|
254 |
with gr.TabItem("3οΈβ£ Agentic Analysis Report", id="tab_agentic_report", visible=AGENTIC_MODULES_LOADED):
|
255 |
# The create_enhanced_report_tab function handles the CSS and HTML structure
|
256 |
+
# MODIFIED: Unpacked 4 values instead of 3
|
257 |
+
agentic_pipeline_status_md, report_selector_dd, report_header_html_display, report_body_markdown_display = \
|
258 |
create_enhanced_report_tab(AGENTIC_MODULES_LOADED)
|
259 |
|
260 |
|
|
|
304 |
if AGENTIC_MODULES_LOADED:
|
305 |
report_selector_dd.change(
|
306 |
fn=update_report_display, # This now calls the enhanced function
|
307 |
+
# MODIFIED: Updated outputs to match the two new display components
|
308 |
inputs=[report_selector_dd, token_state],
|
309 |
+
outputs=[report_header_html_display, report_body_markdown_display],
|
310 |
show_progress="minimal"
|
311 |
)
|
312 |
|
313 |
# Ensure agentic_display_outputs correctly maps to the newly created components
|
314 |
+
# This list must match the outputs of load_and_display_agentic_results
|
315 |
agentic_display_outputs = [
|
316 |
+
agentic_pipeline_status_md, # 0: Status Markdown (hidden)
|
317 |
+
report_selector_dd, # 1: Dropdown for selecting reports
|
318 |
+
key_results_cbg, # 2: Checkbox group for OKRs
|
319 |
+
okr_detail_display_md, # 3: Markdown for detailed OKR display
|
320 |
+
orchestration_raw_results_st, # 4: Raw results state
|
321 |
+
selected_key_result_ids_st, # 5: Selected KR IDs state
|
322 |
+
key_results_for_selection_st, # 6: All KRs for selection state
|
323 |
+
report_header_html_display, # 7: New HTML output for header
|
324 |
+
report_body_markdown_display, # 8: New Markdown output for body
|
325 |
+
reconstruction_cache_st # 9: Reconstruction cache state
|
326 |
]
|
327 |
|
328 |
initial_load_event = org_urn_display.change(
|
|
|
341 |
).then(
|
342 |
fn=load_and_display_agentic_results,
|
343 |
inputs=[token_state, reconstruction_cache_st],
|
344 |
+
# MODIFIED: Updated outputs to match all components returned by load_and_display_agentic_results
|
345 |
outputs=agentic_display_outputs,
|
346 |
show_progress="minimal"
|
347 |
)
|