Barisha commited on
Commit
aa267ab
Β·
verified Β·
1 Parent(s): 19a34f3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -16
app.py CHANGED
@@ -58,39 +58,28 @@ def load_csv(file):
58
 
59
  # ---------- Main Analysis ----------
60
  def analyze(df, selected_kpis):
 
61
 
62
- print("Analyze function triggered")
63
  if df is None or not selected_kpis:
64
  return "❌ Upload CSV and select KPI columns"
65
 
66
- progress(0, desc="Starting analysis...")
67
-
68
  results = []
69
  explanations = []
70
 
71
- total = len(selected_kpis)
72
-
73
- for i, kpi in enumerate(selected_kpis):
74
- progress((i + 1) / total, desc=f"Analyzing {kpi}...")
75
-
76
  vals = df[kpi].dropna().values.tolist()
77
  trend = detect_trend(vals)
78
  score = change_score(vals)
79
-
80
  results.append((kpi, trend, score, vals))
81
 
82
  ranked = sorted(results, key=lambda x: x[2], reverse=True)
83
 
84
- progress(0.85, desc="Generating LLM explanations...")
85
-
86
- # Explain only top 5
87
  for kpi, trend, score, vals in ranked[:5]:
88
  exp = explain(kpi, vals, trend)
89
  explanations.append(f"**{kpi}** β†’ {exp}")
90
 
91
- progress(1.0, desc="Done βœ…")
92
-
93
- # ----- Output -----
94
  text = "## πŸ”₯ Top 5 KPIs with Biggest Change\n"
95
  for kpi, trend, score, _ in ranked[:5]:
96
  text += f"**{kpi}** β†’ {trend} (Score: {score})\n\n"
@@ -105,7 +94,6 @@ def analyze(df, selected_kpis):
105
 
106
  return text
107
 
108
-
109
  # ---------- UI ----------
110
  with gr.Blocks() as demo:
111
  gr.Markdown("# πŸ€– KPI Trend Analyzer with LLM Explanation")
 
58
 
59
  # ---------- Main Analysis ----------
60
  def analyze(df, selected_kpis):
61
+ print("βœ… Analyze function triggered")
62
 
 
63
  if df is None or not selected_kpis:
64
  return "❌ Upload CSV and select KPI columns"
65
 
 
 
66
  results = []
67
  explanations = []
68
 
69
+ for kpi in selected_kpis:
 
 
 
 
70
  vals = df[kpi].dropna().values.tolist()
71
  trend = detect_trend(vals)
72
  score = change_score(vals)
 
73
  results.append((kpi, trend, score, vals))
74
 
75
  ranked = sorted(results, key=lambda x: x[2], reverse=True)
76
 
77
+ # LLM explanation for top 5
 
 
78
  for kpi, trend, score, vals in ranked[:5]:
79
  exp = explain(kpi, vals, trend)
80
  explanations.append(f"**{kpi}** β†’ {exp}")
81
 
82
+ # Output
 
 
83
  text = "## πŸ”₯ Top 5 KPIs with Biggest Change\n"
84
  for kpi, trend, score, _ in ranked[:5]:
85
  text += f"**{kpi}** β†’ {trend} (Score: {score})\n\n"
 
94
 
95
  return text
96
 
 
97
  # ---------- UI ----------
98
  with gr.Blocks() as demo:
99
  gr.Markdown("# πŸ€– KPI Trend Analyzer with LLM Explanation")