Spaces:
Running on Zero
Running on Zero
Deploiement GuindiMa AI (interface Gradio)
Browse files
app.py
CHANGED
|
@@ -73,7 +73,7 @@ from matching.lieux import AVANT_NUMERO, FAUX_AMIS, joli, sans_accents # noqa:
|
|
| 73 |
from matching.stops_matcher import StopsMatcher # noqa: E402
|
| 74 |
from intent.conversation import HORS_SUJET, Intention # noqa: E402
|
| 75 |
from intent.conversation import detecter as detecter_conversation # noqa: E402
|
| 76 |
-
from intent.conversation import signal_trajet # noqa: E402
|
| 77 |
from tts.speak import voix_conversation # noqa: E402
|
| 78 |
from tts.speak import ( # noqa: E402
|
| 79 |
MAX_POSSIBILITES,
|
|
@@ -444,6 +444,31 @@ def _second_essai(audio: np.ndarray, libelle_premier: str) -> tuple[str, str, fl
|
|
| 444 |
raise
|
| 445 |
|
| 446 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 447 |
def _phrase_donne_un_trajet(phrase: str) -> bool:
|
| 448 |
"""La phrase mène-t-elle déjà à un trajet, sans LLM ?
|
| 449 |
|
|
@@ -467,6 +492,9 @@ def _phrase_donne_un_trajet(phrase: str) -> bool:
|
|
| 467 |
if not (local.get("depart") and local.get("arrivee")):
|
| 468 |
return False
|
| 469 |
essai = MATCHER.find_line(local["depart"], local["arrivee"])
|
|
|
|
|
|
|
|
|
|
| 470 |
return bool(essai["found"] or essai["correspondances"])
|
| 471 |
|
| 472 |
|
|
@@ -1334,7 +1362,10 @@ def _pipeline(
|
|
| 1334 |
intent = None
|
| 1335 |
if local.get("depart") and local.get("arrivee"):
|
| 1336 |
essai = MATCHER.find_line(local["depart"], local["arrivee"])
|
| 1337 |
-
|
|
|
|
|
|
|
|
|
|
| 1338 |
intent = {**local, "source": "reseau", "erreur": None}
|
| 1339 |
if intent is None:
|
| 1340 |
intent = extract_intent(phrase, client=_client_llm())
|
|
@@ -1364,6 +1395,13 @@ def _pipeline(
|
|
| 1364 |
depart, arrivee, resultat = local["depart"], local["arrivee"], essai
|
| 1365 |
intent = {**intent, "source": "llm+local"}
|
| 1366 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1367 |
# Compagnie : ce que l'utilisateur a dit à la voix prime sur le bouton.
|
| 1368 |
compagnie_voix = (intent.get("compagnie") or "").strip()
|
| 1369 |
compagnie = compagnie_voix or compagnie_choix or ""
|
|
|
|
| 73 |
from matching.stops_matcher import StopsMatcher # noqa: E402
|
| 74 |
from intent.conversation import HORS_SUJET, Intention # noqa: E402
|
| 75 |
from intent.conversation import detecter as detecter_conversation # noqa: E402
|
| 76 |
+
from intent.conversation import INTENTIONS, signal_trajet # noqa: E402
|
| 77 |
from tts.speak import voix_conversation # noqa: E402
|
| 78 |
from tts.speak import ( # noqa: E402
|
| 79 |
MAX_POSSIBILITES,
|
|
|
|
| 444 |
raise
|
| 445 |
|
| 446 |
|
| 447 |
+
# Départ et arrivée au même endroit : vu en production, Kiriku a écrit
|
| 448 |
+
# « damay dem petersen te maa ngi wakaay » ; « wakaay » n'étant pas reconnu, le
|
| 449 |
+
# LLM a rendu Petersen -> Petersen, et l'app a répondu « À pied environ 0 min »
|
| 450 |
+
# avec des bus au hasard. Même nom, ou marche de moins de 100 m (Palais ->
|
| 451 |
+
# Palais 2) : ce n'est pas un trajet, c'est une extraction incomplète.
|
| 452 |
+
DISTANCE_MEME_LIEU_M = 100
|
| 453 |
+
|
| 454 |
+
# On redemande avec une phrase déjà enregistrée, jamais une phrase nouvelle :
|
| 455 |
+
# « Wax ma fan nga nekk ak fan nga bëgga dem, ma won la bus bi nga wara jël. »
|
| 456 |
+
# (conversation_capacites.wav, validée par le locuteur natif).
|
| 457 |
+
_CAPACITES = next(i for i in INTENTIONS if i.nom == "capacites")
|
| 458 |
+
DEMANDE_MEME_LIEU = Intention("meme_lieu", _CAPACITES.reponse, _CAPACITES.fichier, ())
|
| 459 |
+
|
| 460 |
+
|
| 461 |
+
def _meme_lieu(depart: str, arrivee: str, resultat: dict | None = None) -> bool:
|
| 462 |
+
"""Vrai si départ et arrivée désignent le même endroit (nom ou marche quasi nulle)."""
|
| 463 |
+
if not depart or not arrivee:
|
| 464 |
+
return False
|
| 465 |
+
if sans_accents(depart).lower().strip() == sans_accents(arrivee).lower().strip():
|
| 466 |
+
return True
|
| 467 |
+
a_pied = (resultat or {}).get("a_pied") or {}
|
| 468 |
+
distance = a_pied.get("distance_m")
|
| 469 |
+
return isinstance(distance, (int, float)) and distance <= DISTANCE_MEME_LIEU_M
|
| 470 |
+
|
| 471 |
+
|
| 472 |
def _phrase_donne_un_trajet(phrase: str) -> bool:
|
| 473 |
"""La phrase mène-t-elle déjà à un trajet, sans LLM ?
|
| 474 |
|
|
|
|
| 492 |
if not (local.get("depart") and local.get("arrivee")):
|
| 493 |
return False
|
| 494 |
essai = MATCHER.find_line(local["depart"], local["arrivee"])
|
| 495 |
+
if _meme_lieu(local["depart"], local["arrivee"], essai):
|
| 496 |
+
# Même lieu des deux côtés : l'autre modèle ASR a sa chance.
|
| 497 |
+
return False
|
| 498 |
return bool(essai["found"] or essai["correspondances"])
|
| 499 |
|
| 500 |
|
|
|
|
| 1362 |
intent = None
|
| 1363 |
if local.get("depart") and local.get("arrivee"):
|
| 1364 |
essai = MATCHER.find_line(local["depart"], local["arrivee"])
|
| 1365 |
+
# Même lieu des deux côtés : extraction incomplète, le LLM relit la phrase.
|
| 1366 |
+
if (essai["found"] or essai["correspondances"]) and not _meme_lieu(
|
| 1367 |
+
local["depart"], local["arrivee"], essai
|
| 1368 |
+
):
|
| 1369 |
intent = {**local, "source": "reseau", "erreur": None}
|
| 1370 |
if intent is None:
|
| 1371 |
intent = extract_intent(phrase, client=_client_llm())
|
|
|
|
| 1395 |
depart, arrivee, resultat = local["depart"], local["arrivee"], essai
|
| 1396 |
intent = {**intent, "source": "llm+local"}
|
| 1397 |
|
| 1398 |
+
# Toujours le même lieu après le LLM (qui a relu la phrase entière) : jamais
|
| 1399 |
+
# de bus ni de « À pied 0 min ». On redemande d'où l'usager part et où il va,
|
| 1400 |
+
# avec une phrase déjà enregistrée.
|
| 1401 |
+
if _meme_lieu(depart, arrivee, resultat):
|
| 1402 |
+
quint = _reponse_conversation(phrase, DEMANDE_MEME_LIEU, modele_asr, duree_asr)
|
| 1403 |
+
return quint[:4] + (_mention(intent, modele_asr),), False
|
| 1404 |
+
|
| 1405 |
# Compagnie : ce que l'utilisateur a dit à la voix prime sur le bouton.
|
| 1406 |
compagnie_voix = (intent.get("compagnie") or "").strip()
|
| 1407 |
compagnie = compagnie_voix or compagnie_choix or ""
|