Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 "
|
| 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 =
|
|
|
|
|
|
|
|
|
|
| 41 |
else:
|
| 42 |
-
summary = f"_No label (
|
| 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(
|
| 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 |
-
|
| 77 |
-
"
|
| 78 |
-
"
|
| 79 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
],
|
| 81 |
inputs=[text],
|
| 82 |
-
label="
|
| 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 |
-
|
| 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)
|