Barisha commited on
Commit
e6b58e1
·
verified ·
1 Parent(s): d380ffa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -11
app.py CHANGED
@@ -3,11 +3,13 @@ import pandas as pd
3
  from transformers import pipeline
4
 
5
  # ------------------------------------------------
6
- # Load SLM (polishing only)
7
  # ------------------------------------------------
8
  generator = pipeline(
9
- "text2text-generation",
10
- model="google/flan-t5-small"
 
 
11
  )
12
 
13
  # ------------------------------------------------
@@ -31,7 +33,6 @@ def summarize_secondary(diffs):
31
  avg_change = diffs.abs().mean()
32
  inc_ratio = (diffs > 0).mean()
33
 
34
- # Magnitude descriptor
35
  if avg_change < 0.05:
36
  magnitude = "minor variation"
37
  elif avg_change < 0.2:
@@ -39,7 +40,6 @@ def summarize_secondary(diffs):
39
  else:
40
  magnitude = "notable movement"
41
 
42
- # Direction descriptor
43
  if inc_ratio > 0.7:
44
  direction = "mostly increased"
45
  elif inc_ratio < 0.3:
@@ -79,22 +79,22 @@ def analyze_kpi(csv_file, top_n):
79
  )
80
 
81
  # -------------------------------
82
- # Secondary KPIs sentence (DATA-DRIVEN)
83
  # -------------------------------
84
  secondary_diffs = top_kpis.iloc[1:]["Diff"]
85
  secondary_sentence = summarize_secondary(secondary_diffs)
86
 
87
- # Combined input
88
  model_input = primary_sentence + ". " + secondary_sentence + "."
89
 
90
- # Light smoothing only
91
- summary = generator(
92
  model_input,
93
- max_new_tokens=45,
94
  do_sample=False
95
  )[0]["generated_text"]
96
 
97
- return top_kpis[["Kpi", "Change"]], summary
98
 
99
  # ------------------------------------------------
100
  # Gradio UI (HF Space)
 
3
  from transformers import pipeline
4
 
5
  # ------------------------------------------------
6
+ # Load Qwen-3B (polishing only)
7
  # ------------------------------------------------
8
  generator = pipeline(
9
+ task="text-generation",
10
+ model="Qwen/Qwen2.5-3B-Instruct",
11
+ device_map="auto",
12
+ trust_remote_code=True
13
  )
14
 
15
  # ------------------------------------------------
 
33
  avg_change = diffs.abs().mean()
34
  inc_ratio = (diffs > 0).mean()
35
 
 
36
  if avg_change < 0.05:
37
  magnitude = "minor variation"
38
  elif avg_change < 0.2:
 
40
  else:
41
  magnitude = "notable movement"
42
 
 
43
  if inc_ratio > 0.7:
44
  direction = "mostly increased"
45
  elif inc_ratio < 0.3:
 
79
  )
80
 
81
  # -------------------------------
82
+ # Secondary KPI sentence
83
  # -------------------------------
84
  secondary_diffs = top_kpis.iloc[1:]["Diff"]
85
  secondary_sentence = summarize_secondary(secondary_diffs)
86
 
87
+ # Model input (already well-formed)
88
  model_input = primary_sentence + ". " + secondary_sentence + "."
89
 
90
+ # Qwen generation (polishing only)
91
+ output = generator(
92
  model_input,
93
+ max_new_tokens=60,
94
  do_sample=False
95
  )[0]["generated_text"]
96
 
97
+ return top_kpis[["Kpi", "Change"]], output
98
 
99
  # ------------------------------------------------
100
  # Gradio UI (HF Space)