muffin2006 commited on
Commit
16de5af
Β·
verified Β·
1 Parent(s): 72ca8da

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -14
app.py CHANGED
@@ -8,7 +8,7 @@ from agent import TicketAgent
8
  print("πŸš€ Space starting...")
9
 
10
  # =========================
11
- # 🧠 LAZY MODEL LOADING (HF SAFE)
12
  # =========================
13
  models = {}
14
 
@@ -59,19 +59,27 @@ def run_baseline_all():
59
  try:
60
  rows = []
61
  for d in ["easy","medium","hard"]:
62
- model = get_model(d) # lazy load
63
  score, t = run_task(d)
64
  rows.append([d.upper(), score, score*100, t])
65
- return pd.DataFrame(rows, columns=["Task","Score","Accuracy (%)","Time (s)"])
 
 
 
 
 
66
  except Exception as e:
67
- return pd.DataFrame([[str(e), "", "", ""]], columns=["Task","Score","Accuracy (%)","Time (s)"])
 
 
 
68
 
69
  def process_ticket_ui(text, difficulty):
70
  try:
71
  if not text.strip():
72
  return "Enter ticket!", "", "", "", "", ""
73
 
74
- model = get_model(difficulty) # lazy load
75
 
76
  res = agent.process_ticket(text, difficulty=difficulty)
77
 
@@ -84,7 +92,11 @@ def process_ticket_ui(text, difficulty):
84
 
85
  top3_data = res.get("top3", [])
86
  if isinstance(top3_data, list):
87
- top3 = "\n".join([f"{c}: {p*100:.1f}%" for c,p in top3_data])
 
 
 
 
88
  else:
89
  top3 = "N/A"
90
 
@@ -101,7 +113,7 @@ def process_ticket_ui(text, difficulty):
101
  return f"❌ Error: {str(e)}", "", "", "", "", ""
102
 
103
  # =========================
104
- # 🎨 MODERN UI (UNIQUE)
105
  # =========================
106
 
107
  custom_css = """
@@ -185,7 +197,7 @@ with gr.Blocks(css=custom_css, theme=gr.themes.Soft()) as demo:
185
  # -------------------------
186
  with gr.Tab("πŸ“Š Performance"):
187
  btn_eval = gr.Button("Run Evaluation")
188
- table = gr.Dataframe()
189
 
190
  btn_eval.click(run_baseline_all, outputs=table)
191
 
@@ -194,14 +206,14 @@ with gr.Blocks(css=custom_css, theme=gr.themes.Soft()) as demo:
194
  # -------------------------
195
  with gr.Tab("ℹ️ About"):
196
  gr.Markdown("""
197
- - AI ticket classification
198
- - Priority detection
199
- - Auto routing
200
- - RL simulator
201
  """)
202
 
203
  # =========================
204
- # πŸš€ RUN (HF SAFE)
205
  # =========================
206
  if __name__ == "__main__":
207
- demo.launch()
 
8
  print("πŸš€ Space starting...")
9
 
10
  # =========================
11
+ # 🧠 LAZY MODEL LOADING
12
  # =========================
13
  models = {}
14
 
 
59
  try:
60
  rows = []
61
  for d in ["easy","medium","hard"]:
62
+ get_model(d)
63
  score, t = run_task(d)
64
  rows.append([d.upper(), score, score*100, t])
65
+
66
+ return pd.DataFrame(
67
+ rows,
68
+ columns=["Task","Score","Accuracy (%)","Time (s)"]
69
+ )
70
+
71
  except Exception as e:
72
+ return pd.DataFrame(
73
+ [["ERROR", str(e), "", ""]],
74
+ columns=["Task","Score","Accuracy (%)","Time (s)"]
75
+ )
76
 
77
  def process_ticket_ui(text, difficulty):
78
  try:
79
  if not text.strip():
80
  return "Enter ticket!", "", "", "", "", ""
81
 
82
+ get_model(difficulty)
83
 
84
  res = agent.process_ticket(text, difficulty=difficulty)
85
 
 
92
 
93
  top3_data = res.get("top3", [])
94
  if isinstance(top3_data, list):
95
+ top3 = "\n".join([
96
+ f"{str(c)}: {float(p)*100:.1f}%"
97
+ for c, p in top3_data
98
+ if isinstance(p, (int, float))
99
+ ])
100
  else:
101
  top3 = "N/A"
102
 
 
113
  return f"❌ Error: {str(e)}", "", "", "", "", ""
114
 
115
  # =========================
116
+ # 🎨 UI DESIGN
117
  # =========================
118
 
119
  custom_css = """
 
197
  # -------------------------
198
  with gr.Tab("πŸ“Š Performance"):
199
  btn_eval = gr.Button("Run Evaluation")
200
+ table = gr.Dataframe(type="pandas")
201
 
202
  btn_eval.click(run_baseline_all, outputs=table)
203
 
 
206
  # -------------------------
207
  with gr.Tab("ℹ️ About"):
208
  gr.Markdown("""
209
+ - AI ticket classification
210
+ - Priority detection
211
+ - Auto routing
212
+ - RL simulator
213
  """)
214
 
215
  # =========================
216
+ # πŸš€ RUN (HF FIXED)
217
  # =========================
218
  if __name__ == "__main__":
219
+ demo.launch(share=True)