dipsikha25 commited on
Commit
4294ece
Β·
verified Β·
1 Parent(s): b009565

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +85 -94
app.py CHANGED
@@ -1,116 +1,107 @@
1
- import os
2
- from pathlib import Path
3
- import gradio as gr
4
- import pandas as pd
5
-
6
- # =========================
7
- # CONFIG
8
- # =========================
9
-
10
- PDF_FILE = "data.pdf"
11
- DEFAULT_KPI_EXCEL = "CIA Consolidated KPIs_MetricsGovernance (1).xlsx"
12
-
13
- # =========================
14
- # SAFE EXCEL LOADER
15
- # =========================
16
-
17
- def load_kpi_excel_mapping(excel_path):
18
- try:
19
- df = pd.read_excel(excel_path, engine="openpyxl")
20
- return {"rows": len(df)}
21
- except Exception as e:
22
- print(f"Excel load error: {e}")
23
- return {}
24
-
25
- def load_default_excel_if_present():
26
- try:
27
- if Path(DEFAULT_KPI_EXCEL).exists():
28
- return load_kpi_excel_mapping(DEFAULT_KPI_EXCEL)
29
- except Exception as e:
30
- print(f"Excel error: {e}")
31
- return {}
32
-
33
- # =========================
34
- # CORE LOGIC (SIMPLIFIED SAFE VERSION)
35
- # =========================
36
-
37
- def get_answer(question, audience, excel_mapping=None):
38
- if not question or not question.strip():
39
- return (
40
- "Ask a KPI question to see the summary cards.",
41
- "Please enter a KPI question.",
42
- "",
43
- "",
44
- "",
45
- "No comparison available."
46
- )
47
-
48
- # Dummy safe response (replace with your full logic later)
49
- return (
50
- f"Results for: {question}",
51
- f"Definition of {question}",
52
- f"Business meaning for {audience}",
53
- f"Formula for {question}",
54
- f"Notes for {question}",
55
- "No comparison available."
56
- )
57
-
58
- def clear_all(default_mapping):
59
- return (
60
- "",
61
- "Business User",
62
- "Ask a KPI question to see the summary cards.",
63
- "",
64
- "",
65
- "",
66
- "",
67
- "Comparison results will appear here."
68
- )
69
-
70
- # =========================
71
  # UI
72
- # =========================
73
-
74
- CUSTOM_CSS = """"""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
 
76
  DEFAULT_MAPPING = load_default_excel_if_present()
77
 
78
- with gr.Blocks() as demo:
79
-
80
- gr.HTML(CUSTOM_CSS)
81
 
82
- # βœ… Clean header (no extra text)
83
- gr.HTML("<h2>πŸ’Š Pharma KPI Copilot</h2>")
 
 
 
 
84
 
85
  with gr.Row():
86
 
 
87
  # LEFT PANEL
 
88
  with gr.Column(scale=1):
89
- question = gr.Textbox(
90
- label="Ask KPI question",
91
- placeholder="e.g. OCCP Interactions"
92
- )
93
 
94
- audience = gr.Dropdown(
95
- ["Business User", "Leadership", "Analytics User"],
96
- value="Business User",
97
- label="Explain for"
98
- )
 
 
 
 
 
 
 
 
 
 
99
 
100
  submit_btn = gr.Button("Submit")
101
  clear_btn = gr.Button("Clear")
102
 
 
103
  # RIGHT PANEL
 
104
  with gr.Column(scale=2):
105
- summary = gr.Markdown("Ask a KPI question to see the summary cards.")
106
- definition = gr.Markdown()
107
- business = gr.Markdown()
108
- formula = gr.Markdown()
109
- notes = gr.Markdown()
110
- comparison = gr.Markdown()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
111
 
112
  # =========================
113
- # BUTTON ACTIONS
114
  # =========================
115
 
116
  submit_btn.click(
 
1
+ # =========================================================
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  # UI
3
+ # =========================================================
4
+
5
+ CUSTOM_CSS = """
6
+ body {
7
+ background-color: #f5f7fb;
8
+ }
9
+
10
+ /* Header card */
11
+ .header-card {
12
+ background: #e9ecf8;
13
+ border-radius: 20px;
14
+ padding: 20px;
15
+ margin-bottom: 20px;
16
+ }
17
+
18
+ /* Left input panel */
19
+ .gradio-container .gr-group {
20
+ background: #ffffff;
21
+ border-radius: 12px;
22
+ padding: 15px;
23
+ }
24
+
25
+ /* Summary box (right top) */
26
+ .summary-box {
27
+ border: 1px dashed #d1d5db;
28
+ border-radius: 12px;
29
+ padding: 15px;
30
+ background: #ffffff;
31
+ }
32
+
33
+ /* Buttons */
34
+ button {
35
+ border-radius: 12px !important;
36
+ }
37
+ """
38
 
39
  DEFAULT_MAPPING = load_default_excel_if_present()
40
 
41
+ with gr.Blocks(css=CUSTOM_CSS) as demo:
 
 
42
 
43
+ # βœ… HEADER (clean, no extra text)
44
+ gr.HTML("""
45
+ <div class="header-card">
46
+ <h2>πŸ’Š Pharma KPI Copilot</h2>
47
+ </div>
48
+ """)
49
 
50
  with gr.Row():
51
 
52
+ # =========================
53
  # LEFT PANEL
54
+ # =========================
55
  with gr.Column(scale=1):
 
 
 
 
56
 
57
+ with gr.Group():
58
+ question = gr.Textbox(
59
+ label="Ask KPI question",
60
+ placeholder="e.g. OCCP Interactions"
61
+ )
62
+
63
+ audience = gr.Dropdown(
64
+ ["Business User", "Leadership", "Analytics User"],
65
+ value="Business User",
66
+ label="Explain for"
67
+ )
68
+
69
+ # βœ… REMOVED:
70
+ # ❌ Excel auto-load line
71
+ # ❌ KPI keys count
72
 
73
  submit_btn = gr.Button("Submit")
74
  clear_btn = gr.Button("Clear")
75
 
76
+ # =========================
77
  # RIGHT PANEL
78
+ # =========================
79
  with gr.Column(scale=2):
80
+
81
+ summary = gr.Markdown(
82
+ "Ask a KPI question to see the summary cards.",
83
+ elem_classes="summary-box"
84
+ )
85
+
86
+ # βœ… TABS (restored)
87
+ with gr.Tabs():
88
+ with gr.Tab("Definition"):
89
+ definition = gr.Markdown()
90
+
91
+ with gr.Tab("Business Meaning"):
92
+ business = gr.Markdown()
93
+
94
+ with gr.Tab("Formula"):
95
+ formula = gr.Markdown()
96
+
97
+ with gr.Tab("Notes"):
98
+ notes = gr.Markdown()
99
+
100
+ with gr.Tab("Comparison"):
101
+ comparison = gr.Markdown()
102
 
103
  # =========================
104
+ # ACTIONS
105
  # =========================
106
 
107
  submit_btn.click(