Spaces:
Running
Running
Update ui/insights_ui_generator.py
Browse files- ui/insights_ui_generator.py +46 -26
ui/insights_ui_generator.py
CHANGED
@@ -8,40 +8,59 @@ logger = logging.getLogger(__name__)
|
|
8 |
|
9 |
def format_report_for_display(report_data: Optional[pd.Series]) -> str:
|
10 |
"""
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
Args:
|
15 |
-
report_data: A pandas Series representing a single row from the agentic analysis DataFrame.
|
16 |
-
It should contain 'comprehensive_analysis_text', 'report_type', and 'Created Date'.
|
17 |
-
|
18 |
-
Returns:
|
19 |
-
A Markdown formatted string for the report.
|
20 |
"""
|
21 |
if report_data is None or report_data.empty:
|
22 |
-
return "
|
23 |
-
|
24 |
-
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
report_text = report_data.get('report_text', '*Report content not found.*')
|
27 |
report_type = report_data.get('report_type')
|
28 |
-
created_date_str = report_data.get('Created Date')
|
29 |
-
|
30 |
-
title = "Comprehensive Analysis Report" # Default title
|
31 |
|
|
|
|
|
|
|
|
|
32 |
try:
|
33 |
-
if report_type == '
|
34 |
-
title = "Quarterly Insights Report"
|
|
|
35 |
elif report_type == 'Week' and pd.notna(created_date_str):
|
36 |
-
#
|
37 |
created_date = pd.to_datetime(created_date_str)
|
38 |
-
day_name = created_date.strftime('%A')
|
39 |
-
title = f"{day_name}'s Weekly Update
|
|
|
40 |
except Exception as e:
|
41 |
logger.error(f"Error generating dynamic report title: {e}")
|
42 |
-
# In case of an error,
|
43 |
-
|
44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
|
46 |
|
47 |
def format_report_to_markdown(report_string: Optional[str]) -> str:
|
@@ -76,8 +95,8 @@ def extract_key_results_for_selection(
|
|
76 |
|
77 |
Args:
|
78 |
actionable_okrs_and_tasks_dict: The dictionary representation of TaskExtractionOutput,
|
79 |
-
|
80 |
-
|
81 |
|
82 |
Returns:
|
83 |
A list of dictionaries, where each dictionary represents a Key Result:
|
@@ -237,3 +256,4 @@ def format_single_okr_for_display(
|
|
237 |
md_parts.append("\n*No Key Results matching the 'accepted' filter for this objective.*")
|
238 |
|
239 |
return "\n".join(md_parts)
|
|
|
|
8 |
|
9 |
def format_report_for_display(report_data: Optional[pd.Series]) -> str:
|
10 |
"""
|
11 |
+
Enhanced report formatting with Medium-style typography and layout.
|
12 |
+
This function replaces the original format_report_for_display.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
"""
|
14 |
if report_data is None or report_data.empty:
|
15 |
+
return """
|
16 |
+
<div class="empty-state">
|
17 |
+
<div class="empty-state-icon">π</div>
|
18 |
+
<div class="empty-state-title">Report Not Available</div>
|
19 |
+
<div class="empty-state-description">
|
20 |
+
The selected report could not be loaded. Please try selecting a different report
|
21 |
+
or refresh the page.
|
22 |
+
</div>
|
23 |
+
</div>
|
24 |
+
"""
|
25 |
+
|
26 |
+
# Extract report data
|
27 |
report_text = report_data.get('report_text', '*Report content not found.*')
|
28 |
report_type = report_data.get('report_type')
|
29 |
+
created_date_str = report_data.get('Created Date')
|
|
|
|
|
30 |
|
31 |
+
# Generate dynamic title and subtitle
|
32 |
+
title = "Comprehensive Analysis Report"
|
33 |
+
subtitle = ""
|
34 |
+
|
35 |
try:
|
36 |
+
if report_type == 'Quarter':
|
37 |
+
title = "π Quarterly Insights Report"
|
38 |
+
subtitle = "Strategic analysis of your quarterly performance"
|
39 |
elif report_type == 'Week' and pd.notna(created_date_str):
|
40 |
+
# Ensure pandas is used for datetime conversion
|
41 |
created_date = pd.to_datetime(created_date_str)
|
42 |
+
day_name = created_date.strftime('%A')
|
43 |
+
title = f"π {day_name}'s Weekly Update"
|
44 |
+
subtitle = f"Weekly performance analysis for {created_date.strftime('%B %d, %Y')}"
|
45 |
except Exception as e:
|
46 |
logger.error(f"Error generating dynamic report title: {e}")
|
47 |
+
# In case of an error, default title and no subtitle will be used.
|
48 |
+
|
49 |
+
# Format the report content with the new HTML structure
|
50 |
+
formatted_content = f"""
|
51 |
+
<div class="report-header">
|
52 |
+
<h1>{title}</h1>
|
53 |
+
{f'<p style="font-size: 1.1rem; color: #6b6b6b; margin-bottom: 0;">{subtitle}</p>' if subtitle else ''}
|
54 |
+
</div>
|
55 |
+
|
56 |
+
<div class="report-body">
|
57 |
+
{report_text.strip()}
|
58 |
+
</div>
|
59 |
+
"""
|
60 |
+
|
61 |
+
# Wrap the entire content in a div with the 'markdown' class, which Gradio Markdown component expects
|
62 |
+
# and which is styled by the provided CSS.
|
63 |
+
return formatted_content
|
64 |
|
65 |
|
66 |
def format_report_to_markdown(report_string: Optional[str]) -> str:
|
|
|
95 |
|
96 |
Args:
|
97 |
actionable_okrs_and_tasks_dict: The dictionary representation of TaskExtractionOutput,
|
98 |
+
typically `orchestration_results["actionable_okrs_and_tasks"]`.
|
99 |
+
Expected structure: {'okrs': List[OKR_dict], ...}
|
100 |
|
101 |
Returns:
|
102 |
A list of dictionaries, where each dictionary represents a Key Result:
|
|
|
256 |
md_parts.append("\n*No Key Results matching the 'accepted' filter for this objective.*")
|
257 |
|
258 |
return "\n".join(md_parts)
|
259 |
+
|