BenTouss commited on
Commit
68d7edf
·
verified ·
1 Parent(s): a37f4ce

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -16
app.py CHANGED
@@ -14,7 +14,7 @@ model.eval()
14
  def predict(text: str, threshold: float = 0.6, top_k: int = 8, only_above: bool = True):
15
  text = (text or "").strip()
16
  if not text:
17
- return "_Colle un message à gauche pour lancer l’analyse._", []
18
 
19
  inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=256)
20
  inputs = {k: v.to(device) for k, v in inputs.items()}
@@ -37,9 +37,12 @@ def predict(text: str, threshold: float = 0.6, top_k: int = 8, only_above: bool
37
 
38
  if rows:
39
  best_lbl, best_sc = rows[0][0], rows[0][1]
40
- summary = f"**Top label :** `{best_lbl}` • **score :** `{best_sc}` \n**Results :** {len(rows)} • **threshold :** `{threshold:.2f}`"
 
 
 
41
  else:
42
- summary = f"_No label (thresold `{threshold:.2f}`)._"
43
 
44
  return summary, rows
45
 
@@ -48,9 +51,12 @@ CSS = """
48
  #title { margin-bottom: 0.25rem; }
49
  #subtitle { margin-top: 0; opacity: 0.8; }
50
  .footer { opacity: 0.7; font-size: 0.85rem; text-align: center; margin-top: 0.75rem; }
 
 
 
51
  """
52
 
53
- with gr.Blocks(theme=gr.themes.Soft(), css=CSS) as demo:
54
  gr.Markdown(f"# 🍳 {APP_NAME}", elem_id="title")
55
  gr.Markdown("Customer support message → labels + scores.", elem_id="subtitle")
56
 
@@ -73,13 +79,20 @@ with gr.Blocks(theme=gr.themes.Soft(), css=CSS) as demo:
73
 
74
  gr.Examples(
75
  examples=[
76
- "Bonjour, je n’arrive pas à lancer les vidéos : écran noir et chargement infini. Je suis Premium mais certaines recettes restent verrouillées…",
77
- "Je veux annuler mon abonnement mais je ne trouve pas le faire dans l’app.",
78
- "Paiement refusé alors que ma carte fonctionne ailleurs. Pouvez-vous vérifier ?",
79
- "L’application plante dès que je lance une vidéo en Chromecast.",
 
 
 
 
 
 
 
80
  ],
81
  inputs=[text],
82
- label="Exemples",
83
  )
84
 
85
  with gr.Column(scale=6):
@@ -90,16 +103,12 @@ with gr.Blocks(theme=gr.themes.Soft(), css=CSS) as demo:
90
  label="Predictions",
91
  wrap=True,
92
  interactive=False,
93
- height=320,
94
  )
95
 
96
  gr.Markdown(f"<div class='footer'>Made with ❤️ by Ben • {APP_NAME}</div>")
97
 
98
- run.click(
99
- fn=predict,
100
- inputs=[text, threshold, top_k, only_above],
101
- outputs=[summary, table],
102
- )
103
  clear.add([text, summary, table])
104
 
105
- demo.launch()
 
14
  def predict(text: str, threshold: float = 0.6, top_k: int = 8, only_above: bool = True):
15
  text = (text or "").strip()
16
  if not text:
17
+ return "_Paste a message on the left to start._", []
18
 
19
  inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=256)
20
  inputs = {k: v.to(device) for k, v in inputs.items()}
 
37
 
38
  if rows:
39
  best_lbl, best_sc = rows[0][0], rows[0][1]
40
+ summary = (
41
+ f"**Top label:** `{best_lbl}` • **score:** `{best_sc}` \n"
42
+ f"**Results:** {len(rows)} • **threshold:** `{threshold:.2f}`"
43
+ )
44
  else:
45
+ summary = f"_No label (threshold `{threshold:.2f}`). Try lowering it._"
46
 
47
  return summary, rows
48
 
 
51
  #title { margin-bottom: 0.25rem; }
52
  #subtitle { margin-top: 0; opacity: 0.8; }
53
  .footer { opacity: 0.7; font-size: 0.85rem; text-align: center; margin-top: 0.75rem; }
54
+
55
+ /* Force a nicer dataframe area without using height= */
56
+ #pred_table { min-height: 320px; }
57
  """
58
 
59
+ with gr.Blocks() as demo:
60
  gr.Markdown(f"# 🍳 {APP_NAME}", elem_id="title")
61
  gr.Markdown("Customer support message → labels + scores.", elem_id="subtitle")
62
 
 
79
 
80
  gr.Examples(
81
  examples=[
82
+ # FR
83
+ "Bonjour,\nJe n’arrive pas à lancer les vidéos depuis hier soir : écran noir et chargement infini. "
84
+ "Je suis Premium (paiement OK) mais certaines recettes restent verrouillées. Pouvez-vous vérifier mon compte ?\nMerci !",
85
+ # EN
86
+ "Hi,\nSince yesterday evening I can't play any videos: the screen stays black and keeps buffering. "
87
+ "I'm a Premium subscriber (payment went through), but some recipes are still locked. "
88
+ "Could you please check my account?\nThanks!",
89
+ # DE
90
+ "Hallo,\nseit gestern Abend kann ich keine Videos mehr abspielen: Der Bildschirm bleibt schwarz und es lädt endlos. "
91
+ "Ich habe ein Premium-Abo (Zahlung ist erfolgt), aber einige Rezepte sind weiterhin gesperrt. "
92
+ "Können Sie bitte mein Konto überprüfen?\nVielen Dank!"
93
  ],
94
  inputs=[text],
95
+ label="Examples (FR / EN / DE)",
96
  )
97
 
98
  with gr.Column(scale=6):
 
103
  label="Predictions",
104
  wrap=True,
105
  interactive=False,
106
+ elem_id="pred_table",
107
  )
108
 
109
  gr.Markdown(f"<div class='footer'>Made with ❤️ by Ben • {APP_NAME}</div>")
110
 
111
+ run.click(fn=predict, inputs=[text, threshold, top_k, only_above], outputs=[summary, table])
 
 
 
 
112
  clear.add([text, summary, table])
113
 
114
+ demo.launch(theme=gr.themes.Soft(), css=CSS)