Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -466,6 +466,7 @@ def parse_doc_entry(doc, audience, match_info=None, forced_kpi_name=None, excel_
|
|
| 466 |
non_formula_lines = remove_formula_lines(lines, formula)
|
| 467 |
|
| 468 |
kpi_name = extract_named_field(non_formula_lines, ['Name'])
|
|
|
|
| 469 |
measure_name = extract_named_field(non_formula_lines, ['Measure name in the PBI', 'Measure Name'])
|
| 470 |
if forced_kpi_name and (not kpi_name or normalize_loose(kpi_name) == 'not found'):
|
| 471 |
kpi_name = forced_kpi_name
|
|
@@ -489,21 +490,35 @@ def parse_doc_entry(doc, audience, match_info=None, forced_kpi_name=None, excel_
|
|
| 489 |
notes = []
|
| 490 |
if kpi_name:
|
| 491 |
notes.append(f"**KPI Name:** {fix_pdf_text(kpi_name)}")
|
|
|
|
|
|
|
| 492 |
if measure_name:
|
| 493 |
notes.append(f"**Power BI Measure:** {fix_pdf_text(measure_name)}")
|
| 494 |
if report_sources:
|
| 495 |
notes.append(f"**Report / Offering Presence (Yes columns):** {', '.join(report_sources)}")
|
|
|
|
|
|
|
| 496 |
if extra_excel_info.get('Placement in Offering'):
|
| 497 |
notes.append(f"**Placement in Offering:** {extra_excel_info['Placement in Offering']}")
|
| 498 |
if extra_excel_info.get('Calculated at:'):
|
| 499 |
notes.append(f"**Calculated at:** {extra_excel_info['Calculated at:']}")
|
| 500 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 501 |
|
| 502 |
return {
|
| 503 |
'doc': doc,
|
| 504 |
'page': doc.metadata.get('page'),
|
| 505 |
'context': context,
|
| 506 |
'kpi_name': fix_pdf_text(kpi_name) or 'Not found',
|
|
|
|
| 507 |
'measure_name': fix_pdf_text(measure_name) or 'Not found',
|
| 508 |
'definition': fix_pdf_text(definition),
|
| 509 |
'business': build_business_meaning(audience, kpi_name, measure_name),
|
|
@@ -983,18 +998,19 @@ button[role='tab'][aria-selected='true'] { color: var(--primary) !important; bor
|
|
| 983 |
|
| 984 |
DEFAULT_MAPPING = load_default_excel_if_present()
|
| 985 |
DEFAULT_STATUS = (
|
| 986 |
-
f"Auto-loaded Excel: mapped KPI keys: {len(DEFAULT_MAPPING)}" if Path(DEFAULT_KPI_EXCEL).exists() else
|
| 987 |
f"Auto-load Excel not found: place '{DEFAULT_KPI_EXCEL}' next to app.py"
|
| 988 |
)
|
| 989 |
|
|
|
|
| 990 |
with gr.Blocks() as demo:
|
| 991 |
gr.HTML(CUSTOM_CSS)
|
| 992 |
gr.HTML("""
|
| 993 |
<div class='hero'>
|
| 994 |
-
<div class='hero-title'>💊 Pharma KPI
|
| 995 |
<p class='hero-subtitle'>
|
| 996 |
-
|
| 997 |
-
|
| 998 |
</p>
|
| 999 |
</div>
|
| 1000 |
""")
|
|
@@ -1006,7 +1022,7 @@ with gr.Blocks() as demo:
|
|
| 1006 |
excel_status = gr.Markdown(DEFAULT_STATUS)
|
| 1007 |
submit_btn = gr.Button('Submit', variant='primary')
|
| 1008 |
clear_btn = gr.Button('Clear')
|
| 1009 |
-
|
| 1010 |
|
| 1011 |
with gr.Column(scale=8, elem_classes=['panel']):
|
| 1012 |
summary_cards = gr.HTML('<div class="empty-state">Ask a KPI question to see the summary cards.</div>')
|
|
@@ -1080,4 +1096,4 @@ with gr.Blocks() as demo:
|
|
| 1080 |
],
|
| 1081 |
)
|
| 1082 |
|
| 1083 |
-
demo.launch()
|
|
|
|
| 466 |
non_formula_lines = remove_formula_lines(lines, formula)
|
| 467 |
|
| 468 |
kpi_name = extract_named_field(non_formula_lines, ['Name'])
|
| 469 |
+
kpi_id = extract_named_field(non_formula_lines, ['KPI ID from KPI Glossary', 'KPI ID'])
|
| 470 |
measure_name = extract_named_field(non_formula_lines, ['Measure name in the PBI', 'Measure Name'])
|
| 471 |
if forced_kpi_name and (not kpi_name or normalize_loose(kpi_name) == 'not found'):
|
| 472 |
kpi_name = forced_kpi_name
|
|
|
|
| 490 |
notes = []
|
| 491 |
if kpi_name:
|
| 492 |
notes.append(f"**KPI Name:** {fix_pdf_text(kpi_name)}")
|
| 493 |
+
if kpi_id:
|
| 494 |
+
notes.append(f"**KPI ID:** {fix_pdf_text(kpi_id)}")
|
| 495 |
if measure_name:
|
| 496 |
notes.append(f"**Power BI Measure:** {fix_pdf_text(measure_name)}")
|
| 497 |
if report_sources:
|
| 498 |
notes.append(f"**Report / Offering Presence (Yes columns):** {', '.join(report_sources)}")
|
| 499 |
+
if matched_rows:
|
| 500 |
+
notes.append(f"**Matched Excel Row Count:** {len(matched_rows)}")
|
| 501 |
if extra_excel_info.get('Placement in Offering'):
|
| 502 |
notes.append(f"**Placement in Offering:** {extra_excel_info['Placement in Offering']}")
|
| 503 |
if extra_excel_info.get('Calculated at:'):
|
| 504 |
notes.append(f"**Calculated at:** {extra_excel_info['Calculated at:']}")
|
| 505 |
+
if extra_excel_info.get('Domain'):
|
| 506 |
+
notes.append(f"**Domain:** {extra_excel_info['Domain']}")
|
| 507 |
+
if extra_excel_info.get('Interaction'):
|
| 508 |
+
notes.append(f"**Interaction:** {extra_excel_info['Interaction']}")
|
| 509 |
+
if extra_excel_info.get('Channels'):
|
| 510 |
+
notes.append(f"**Channels:** {extra_excel_info['Channels']}")
|
| 511 |
+
if doc.metadata.get('page') is not None:
|
| 512 |
+
notes.append(f"**Page:** {doc.metadata['page'] + 1}")
|
| 513 |
+
if match_info:
|
| 514 |
+
notes.append(f"**Primary Search Match:** {match_info}")
|
| 515 |
|
| 516 |
return {
|
| 517 |
'doc': doc,
|
| 518 |
'page': doc.metadata.get('page'),
|
| 519 |
'context': context,
|
| 520 |
'kpi_name': fix_pdf_text(kpi_name) or 'Not found',
|
| 521 |
+
'kpi_id': fix_pdf_text(kpi_id) or 'Not found',
|
| 522 |
'measure_name': fix_pdf_text(measure_name) or 'Not found',
|
| 523 |
'definition': fix_pdf_text(definition),
|
| 524 |
'business': build_business_meaning(audience, kpi_name, measure_name),
|
|
|
|
| 998 |
|
| 999 |
DEFAULT_MAPPING = load_default_excel_if_present()
|
| 1000 |
DEFAULT_STATUS = (
|
| 1001 |
+
f"Auto-loaded Excel: {DEFAULT_KPI_EXCEL} | mapped KPI keys: {len(DEFAULT_MAPPING)}" if Path(DEFAULT_KPI_EXCEL).exists() else
|
| 1002 |
f"Auto-load Excel not found: place '{DEFAULT_KPI_EXCEL}' next to app.py"
|
| 1003 |
)
|
| 1004 |
|
| 1005 |
+
|
| 1006 |
with gr.Blocks() as demo:
|
| 1007 |
gr.HTML(CUSTOM_CSS)
|
| 1008 |
gr.HTML("""
|
| 1009 |
<div class='hero'>
|
| 1010 |
+
<div class='hero-title'>💊 Pharma KPI Chatbot</div>
|
| 1011 |
<p class='hero-subtitle'>
|
| 1012 |
+
This is an AI-powered solution for OneCI applications that helps business users quickly access, analyze, and understand key KPIs through natural language queries.
|
| 1013 |
+
It enables faster business insights, improved decision-making, and a more efficient reporting experience across OneCI platforms.
|
| 1014 |
</p>
|
| 1015 |
</div>
|
| 1016 |
""")
|
|
|
|
| 1022 |
excel_status = gr.Markdown(DEFAULT_STATUS)
|
| 1023 |
submit_btn = gr.Button('Submit', variant='primary')
|
| 1024 |
clear_btn = gr.Button('Clear')
|
| 1025 |
+
|
| 1026 |
|
| 1027 |
with gr.Column(scale=8, elem_classes=['panel']):
|
| 1028 |
summary_cards = gr.HTML('<div class="empty-state">Ask a KPI question to see the summary cards.</div>')
|
|
|
|
| 1096 |
],
|
| 1097 |
)
|
| 1098 |
|
| 1099 |
+
demo.launch()
|