Spaces:
Running
Running
cheikhaidev-ui Claude Sonnet 4.6 commited on
Commit ·
349eedf
1
Parent(s): 76aefa2
feat(app): sliders lecture seule pour polarité et clarté
Browse files- gr.Slider(interactive=False) remplace les barres ASCII ─●─ et ████░
- Polarité [-1, 1] : track CSS rouge→gris→vert, pouce accentColor via JS
- Clarté [0, 100] : track CSS rouge→orange→vert, même mécanique JS
- setInterval 150ms interpolant rgb() selon valeur courante (accentColor)
- run_analysis passe de 5 à 7 sorties (+ polarity float, + clarity int)
- Valeur de polarité affichée en span coloré vert/rouge/gris dans Synthèse
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
app.py
CHANGED
|
@@ -12,14 +12,15 @@ from src import feedback as feedback_mod
|
|
| 12 |
LANG_MAP = {"Détection auto": None, "Français": "fr", "Anglais": "en"}
|
| 13 |
|
| 14 |
|
| 15 |
-
def run_analysis(text: str, lang_choice: str) -> tuple
|
| 16 |
"""
|
| 17 |
-
Orchestre les trois modules et retourne
|
| 18 |
-
|
|
|
|
| 19 |
"""
|
| 20 |
if not text or not text.strip():
|
| 21 |
empty = "_Entrez un texte pour lancer l'analyse._"
|
| 22 |
-
return empty, empty, empty, empty, empty
|
| 23 |
|
| 24 |
lang = LANG_MAP.get(lang_choice)
|
| 25 |
|
|
@@ -29,10 +30,12 @@ def run_analysis(text: str, lang_choice: str) -> tuple[str, str, str, str, str]:
|
|
| 29 |
|
| 30 |
return (
|
| 31 |
_render_summary(fb["summary"], sent),
|
|
|
|
| 32 |
_render_sentiment(fb["sentiment"], sent),
|
| 33 |
_render_speech(fb, spch),
|
| 34 |
_render_structure(fb["structure"], spch),
|
| 35 |
_render_clarity(fb["clarity"], spch),
|
|
|
|
| 36 |
)
|
| 37 |
|
| 38 |
|
|
@@ -43,12 +46,12 @@ def run_analysis(text: str, lang_choice: str) -> tuple[str, str, str, str, str]:
|
|
| 43 |
def _render_summary(summary: str, sent: dict) -> str:
|
| 44 |
lang_label = {"fr": "Français", "en": "Anglais"}.get(sent["language"], "Inconnu")
|
| 45 |
polarity = sent["polarity"]
|
| 46 |
-
|
| 47 |
return (
|
| 48 |
f"### Synthèse\n"
|
| 49 |
f"{summary}\n\n"
|
| 50 |
-
f"**Langue détectée :** {lang_label}
|
| 51 |
-
f
|
| 52 |
)
|
| 53 |
|
| 54 |
|
|
@@ -82,24 +85,8 @@ def _render_structure(lines: list[str], spch: dict) -> str:
|
|
| 82 |
|
| 83 |
|
| 84 |
def _render_clarity(lines: list[str], spch: dict) -> str:
|
| 85 |
-
c = spch["clarity"]
|
| 86 |
-
score = c["clarity_score"]
|
| 87 |
-
bar = _score_bar(score)
|
| 88 |
body = "\n\n".join(lines)
|
| 89 |
-
return f"### Clarté\n{
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
def _polarity_bar(polarity: float) -> str:
|
| 93 |
-
pos = int((polarity + 1) / 2 * 20)
|
| 94 |
-
pos = max(0, min(20, pos))
|
| 95 |
-
bar = "─" * pos + "●" + "─" * (20 - pos)
|
| 96 |
-
return f"`−1 {bar} +1`"
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
def _score_bar(score: int) -> str:
|
| 100 |
-
filled = int(score / 100 * 20)
|
| 101 |
-
bar = "█" * filled + "░" * (20 - filled)
|
| 102 |
-
return f"`{bar}` **{score}/100**"
|
| 103 |
|
| 104 |
|
| 105 |
# ---------------------------------------------------------------------------
|
|
@@ -166,7 +153,27 @@ THEME = gr.themes.Base(
|
|
| 166 |
slider_color_dark="#6366f1",
|
| 167 |
)
|
| 168 |
|
| 169 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 170 |
|
| 171 |
CSS = """
|
| 172 |
/* ── Header ───────────────────────────────────────────────────────── */
|
|
@@ -247,6 +254,31 @@ CSS = """
|
|
| 247 |
color: #a5b4fc !important;
|
| 248 |
}
|
| 249 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 250 |
/* ── Container & spacing ──────────────────────────────────────────── */
|
| 251 |
.gradio-container { max-width: 1300px !important; padding: 1.5rem 2rem !important; }
|
| 252 |
|
|
@@ -288,20 +320,31 @@ with gr.Blocks(title="LinguaScope", js=_DARK_JS, css=CSS) as demo:
|
|
| 288 |
)
|
| 289 |
|
| 290 |
with gr.Column(scale=3, elem_classes=["ls-results-col"]):
|
| 291 |
-
out_summary
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 292 |
with gr.Row():
|
| 293 |
out_sentiment = gr.Markdown(elem_classes=["ls-card"])
|
| 294 |
out_speech = gr.Markdown(elem_classes=["ls-card"])
|
| 295 |
with gr.Row():
|
| 296 |
out_structure = gr.Markdown(elem_classes=["ls-card"])
|
| 297 |
out_clarity = gr.Markdown(elem_classes=["ls-card"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 298 |
|
| 299 |
-
outputs = [out_summary, out_sentiment, out_speech,
|
|
|
|
| 300 |
|
| 301 |
submit_btn.click(fn=run_analysis, inputs=[text_input, lang_radio], outputs=outputs)
|
| 302 |
text_input.submit(fn=run_analysis, inputs=[text_input, lang_radio], outputs=outputs)
|
| 303 |
clear_btn.click(
|
| 304 |
-
fn=lambda: ("", "Détection auto"
|
| 305 |
outputs=[text_input, lang_radio] + outputs,
|
| 306 |
)
|
| 307 |
|
|
|
|
| 12 |
LANG_MAP = {"Détection auto": None, "Français": "fr", "Anglais": "en"}
|
| 13 |
|
| 14 |
|
| 15 |
+
def run_analysis(text: str, lang_choice: str) -> tuple:
|
| 16 |
"""
|
| 17 |
+
Orchestre les trois modules et retourne 7 valeurs pour les composants Gradio :
|
| 18 |
+
summary_md, polarity_float, sentiment_md, speech_md,
|
| 19 |
+
structure_md, clarity_md, clarity_score_int
|
| 20 |
"""
|
| 21 |
if not text or not text.strip():
|
| 22 |
empty = "_Entrez un texte pour lancer l'analyse._"
|
| 23 |
+
return empty, 0.0, empty, empty, empty, empty, 0
|
| 24 |
|
| 25 |
lang = LANG_MAP.get(lang_choice)
|
| 26 |
|
|
|
|
| 30 |
|
| 31 |
return (
|
| 32 |
_render_summary(fb["summary"], sent),
|
| 33 |
+
sent["polarity"],
|
| 34 |
_render_sentiment(fb["sentiment"], sent),
|
| 35 |
_render_speech(fb, spch),
|
| 36 |
_render_structure(fb["structure"], spch),
|
| 37 |
_render_clarity(fb["clarity"], spch),
|
| 38 |
+
spch["clarity"]["clarity_score"],
|
| 39 |
)
|
| 40 |
|
| 41 |
|
|
|
|
| 46 |
def _render_summary(summary: str, sent: dict) -> str:
|
| 47 |
lang_label = {"fr": "Français", "en": "Anglais"}.get(sent["language"], "Inconnu")
|
| 48 |
polarity = sent["polarity"]
|
| 49 |
+
pol_color = "#22c55e" if polarity > 0.1 else "#ef4444" if polarity < -0.1 else "#94a3b8"
|
| 50 |
return (
|
| 51 |
f"### Synthèse\n"
|
| 52 |
f"{summary}\n\n"
|
| 53 |
+
f"**Langue détectée :** {lang_label} · "
|
| 54 |
+
f'**Polarité** <span style="color:{pol_color};font-weight:700">{polarity:+.4f}</span>'
|
| 55 |
)
|
| 56 |
|
| 57 |
|
|
|
|
| 85 |
|
| 86 |
|
| 87 |
def _render_clarity(lines: list[str], spch: dict) -> str:
|
|
|
|
|
|
|
|
|
|
| 88 |
body = "\n\n".join(lines)
|
| 89 |
+
return f"### Clarté\n{body}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
|
| 91 |
|
| 92 |
# ---------------------------------------------------------------------------
|
|
|
|
| 153 |
slider_color_dark="#6366f1",
|
| 154 |
)
|
| 155 |
|
| 156 |
+
# Force dark mode + polling accent-color dynamique sur les sliders
|
| 157 |
+
_DARK_JS = """() => {
|
| 158 |
+
document.documentElement.classList.add('dark');
|
| 159 |
+
|
| 160 |
+
function lerp(a, b, t) { return a + (b - a) * t; }
|
| 161 |
+
|
| 162 |
+
function pctToColor(pct) {
|
| 163 |
+
const r = pct < 0.5 ? 239 : Math.round(lerp(239, 34, (pct - 0.5) * 2));
|
| 164 |
+
const g = pct < 0.5 ? Math.round(lerp(68, 197, pct * 2)) : 197;
|
| 165 |
+
const b = 68;
|
| 166 |
+
return `rgb(${r},${g},${b})`;
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
setInterval(() => {
|
| 170 |
+
const pol = document.querySelector('.ls-slider-polarity input[type="range"]');
|
| 171 |
+
if (pol) pol.style.accentColor = pctToColor((parseFloat(pol.value) + 1) / 2);
|
| 172 |
+
|
| 173 |
+
const clr = document.querySelector('.ls-slider-clarity input[type="range"]');
|
| 174 |
+
if (clr) clr.style.accentColor = pctToColor(parseFloat(clr.value) / 100);
|
| 175 |
+
}, 150);
|
| 176 |
+
}"""
|
| 177 |
|
| 178 |
CSS = """
|
| 179 |
/* ── Header ───────────────────────────────────────────────────────── */
|
|
|
|
| 254 |
color: #a5b4fc !important;
|
| 255 |
}
|
| 256 |
|
| 257 |
+
/* ── Sliders (gradient track + accent-color via JS) ──────────────── */
|
| 258 |
+
.ls-slider-polarity input[type="range"],
|
| 259 |
+
.ls-slider-clarity input[type="range"] {
|
| 260 |
+
cursor: default !important;
|
| 261 |
+
height: 6px;
|
| 262 |
+
}
|
| 263 |
+
|
| 264 |
+
.ls-slider-polarity input[type="range"]::-webkit-slider-runnable-track {
|
| 265 |
+
background: linear-gradient(to right, #ef4444 0%, #64748b 50%, #22c55e 100%);
|
| 266 |
+
height: 6px; border-radius: 4px;
|
| 267 |
+
}
|
| 268 |
+
.ls-slider-polarity input[type="range"]::-moz-range-track {
|
| 269 |
+
background: linear-gradient(to right, #ef4444 0%, #64748b 50%, #22c55e 100%);
|
| 270 |
+
height: 6px; border-radius: 4px;
|
| 271 |
+
}
|
| 272 |
+
|
| 273 |
+
.ls-slider-clarity input[type="range"]::-webkit-slider-runnable-track {
|
| 274 |
+
background: linear-gradient(to right, #ef4444 0%, #f59e0b 45%, #22c55e 100%);
|
| 275 |
+
height: 6px; border-radius: 4px;
|
| 276 |
+
}
|
| 277 |
+
.ls-slider-clarity input[type="range"]::-moz-range-track {
|
| 278 |
+
background: linear-gradient(to right, #ef4444 0%, #f59e0b 45%, #22c55e 100%);
|
| 279 |
+
height: 6px; border-radius: 4px;
|
| 280 |
+
}
|
| 281 |
+
|
| 282 |
/* ── Container & spacing ──────────────────────────────────────────── */
|
| 283 |
.gradio-container { max-width: 1300px !important; padding: 1.5rem 2rem !important; }
|
| 284 |
|
|
|
|
| 320 |
)
|
| 321 |
|
| 322 |
with gr.Column(scale=3, elem_classes=["ls-results-col"]):
|
| 323 |
+
out_summary = gr.Markdown(elem_classes=["ls-summary"])
|
| 324 |
+
slider_polarity = gr.Slider(
|
| 325 |
+
minimum=-1, maximum=1, step=0.0001, value=0,
|
| 326 |
+
interactive=False, label="Polarité ( −1 négatif · 0 neutre · +1 positif )",
|
| 327 |
+
elem_classes=["ls-slider-polarity"],
|
| 328 |
+
)
|
| 329 |
with gr.Row():
|
| 330 |
out_sentiment = gr.Markdown(elem_classes=["ls-card"])
|
| 331 |
out_speech = gr.Markdown(elem_classes=["ls-card"])
|
| 332 |
with gr.Row():
|
| 333 |
out_structure = gr.Markdown(elem_classes=["ls-card"])
|
| 334 |
out_clarity = gr.Markdown(elem_classes=["ls-card"])
|
| 335 |
+
slider_clarity = gr.Slider(
|
| 336 |
+
minimum=0, maximum=100, step=1, value=0,
|
| 337 |
+
interactive=False, label="Score de clarté ( 0 insuffisant · 100 excellent )",
|
| 338 |
+
elem_classes=["ls-slider-clarity"],
|
| 339 |
+
)
|
| 340 |
|
| 341 |
+
outputs = [out_summary, slider_polarity, out_sentiment, out_speech,
|
| 342 |
+
out_structure, out_clarity, slider_clarity]
|
| 343 |
|
| 344 |
submit_btn.click(fn=run_analysis, inputs=[text_input, lang_radio], outputs=outputs)
|
| 345 |
text_input.submit(fn=run_analysis, inputs=[text_input, lang_radio], outputs=outputs)
|
| 346 |
clear_btn.click(
|
| 347 |
+
fn=lambda: ("", "Détection auto", "", 0.0, "", "", "", "", 0),
|
| 348 |
outputs=[text_input, lang_radio] + outputs,
|
| 349 |
)
|
| 350 |
|