Spaces:
Running
Running
Update ui/insights_ui_generator.py
Browse files- ui/insights_ui_generator.py +27 -27
ui/insights_ui_generator.py
CHANGED
@@ -6,13 +6,23 @@ import pandas as pd
|
|
6 |
logger = logging.getLogger(__name__)
|
7 |
|
8 |
|
9 |
-
def format_report_for_display(report_data: Optional[pd.Series]) -> str:
|
10 |
"""
|
11 |
-
Enhanced report formatting with
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
"""
|
14 |
if report_data is None or report_data.empty:
|
15 |
-
|
16 |
<div class="empty-state">
|
17 |
<div class="empty-state-icon">📄</div>
|
18 |
<div class="empty-state-title">Report Not Available</div>
|
@@ -22,8 +32,10 @@ def format_report_for_display(report_data: Optional[pd.Series]) -> str:
|
|
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')
|
@@ -46,44 +58,32 @@ def format_report_for_display(report_data: Optional[pd.Series]) -> str:
|
|
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
|
50 |
-
|
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 |
-
#
|
62 |
-
|
63 |
-
|
|
|
64 |
|
65 |
|
66 |
def format_report_to_markdown(report_string: Optional[str]) -> str:
|
67 |
"""
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
report_string: The raw text report from the orchestrator.
|
73 |
-
|
74 |
-
Returns:
|
75 |
-
A Markdown formatted string.
|
76 |
"""
|
77 |
if not report_string or not report_string.strip():
|
78 |
return "## Comprehensive Analysis Report\n\n*No analysis report was generated, or an error occurred during its generation.*"
|
79 |
|
80 |
# Simple formatting for now. Could be enhanced (e.g., looking for patterns like "Section X:" to make them H3)
|
81 |
-
# Ensure paragraphs are separated. Replace multiple newlines with double newlines for Markdown paragraphs.
|
82 |
-
# report_string_cleaned = re.sub(r'\n\s*\n', '\n\n', report_string.strip())
|
83 |
-
|
84 |
formatted_report = f"## Comprehensive Analysis Report\n\n{report_string.strip()}"
|
85 |
-
# You might add more sophisticated parsing here if your LLM output for the report
|
86 |
-
# has a consistent structure that can be converted to richer Markdown.
|
87 |
return formatted_report
|
88 |
|
89 |
def extract_key_results_for_selection(
|
|
|
6 |
logger = logging.getLogger(__name__)
|
7 |
|
8 |
|
9 |
+
def format_report_for_display(report_data: Optional[pd.Series]) -> Dict[str, str]:
|
10 |
"""
|
11 |
+
Enhanced report formatting. Returns a dictionary with separate HTML for the header
|
12 |
+
and Markdown for the report body, allowing flexible rendering.
|
13 |
+
|
14 |
+
Args:
|
15 |
+
report_data: A pandas Series representing a single row from the agentic analysis DataFrame.
|
16 |
+
It should contain 'report_text', 'report_type', and 'Created Date'.
|
17 |
+
|
18 |
+
Returns:
|
19 |
+
A dictionary with 'header_html' and 'body_markdown' keys.
|
20 |
+
'header_html' contains the HTML for the report title and subtitle.
|
21 |
+
'body_markdown' contains the raw Markdown text for the report body.
|
22 |
+
If data is invalid, it returns empty state HTML for both.
|
23 |
"""
|
24 |
if report_data is None or report_data.empty:
|
25 |
+
empty_state_html = """
|
26 |
<div class="empty-state">
|
27 |
<div class="empty-state-icon">📄</div>
|
28 |
<div class="empty-state-title">Report Not Available</div>
|
|
|
32 |
</div>
|
33 |
</div>
|
34 |
"""
|
35 |
+
return {'header_html': '', 'body_markdown': empty_state_html}
|
36 |
|
37 |
# Extract report data
|
38 |
+
# Ensure 'report_text' is treated as raw text that will be interpreted as Markdown
|
39 |
report_text = report_data.get('report_text', '*Report content not found.*')
|
40 |
report_type = report_data.get('report_type')
|
41 |
created_date_str = report_data.get('Created Date')
|
|
|
58 |
logger.error(f"Error generating dynamic report title: {e}")
|
59 |
# In case of an error, default title and no subtitle will be used.
|
60 |
|
61 |
+
# Format the report header HTML
|
62 |
+
header_html = f"""
|
63 |
+
<div class="report-header-content">
|
64 |
<h1>{title}</h1>
|
65 |
{f'<p style="font-size: 1.1rem; color: #6b6b6b; margin-bottom: 0;">{subtitle}</p>' if subtitle else ''}
|
66 |
</div>
|
|
|
|
|
|
|
|
|
67 |
"""
|
68 |
|
69 |
+
# The report_text itself should be the raw Markdown for the body
|
70 |
+
body_markdown = report_text.strip()
|
71 |
+
|
72 |
+
return {'header_html': header_html, 'body_markdown': body_markdown}
|
73 |
|
74 |
|
75 |
def format_report_to_markdown(report_string: Optional[str]) -> str:
|
76 |
"""
|
77 |
+
This function was previously for general Markdown formatting.
|
78 |
+
Given the new structure where 'format_report_for_display' handles the split,
|
79 |
+
this function might become redundant or repurposed.
|
80 |
+
Keeping it for now but noting its potential redundancy depending on upstream calls.
|
|
|
|
|
|
|
|
|
81 |
"""
|
82 |
if not report_string or not report_string.strip():
|
83 |
return "## Comprehensive Analysis Report\n\n*No analysis report was generated, or an error occurred during its generation.*"
|
84 |
|
85 |
# Simple formatting for now. Could be enhanced (e.g., looking for patterns like "Section X:" to make them H3)
|
|
|
|
|
|
|
86 |
formatted_report = f"## Comprehensive Analysis Report\n\n{report_string.strip()}"
|
|
|
|
|
87 |
return formatted_report
|
88 |
|
89 |
def extract_key_results_for_selection(
|