PythonMindset commited on
Commit
a53d477
·
verified ·
1 Parent(s): a6e9dd8

Deploiement GuindiMa AI (interface Gradio)

Browse files
Files changed (1) hide show
  1. app.py +21 -6
app.py CHANGED
@@ -73,6 +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 tts.speak import voix_conversation # noqa: E402
77
  from tts.speak import ( # noqa: E402
78
  MAX_POSSIBILITES,
@@ -454,8 +455,14 @@ def _phrase_donne_un_trajet(phrase: str) -> bool:
454
  if not phrase or phrase.startswith(ERREUR_ASR):
455
  return False
456
  local = extract_local(phrase)
457
- if not (local.get("depart") or local.get("arrivee")) and detecter_conversation(phrase):
458
- # « Salam » est compris : inutile de re-transcrire avec l'autre modèle.
 
 
 
 
 
 
459
  return True
460
  if not (local.get("depart") and local.get("arrivee")):
461
  return False
@@ -1314,10 +1321,15 @@ def _pipeline(
1314
  # Liberté 6). Le LLM ne sert que si elle ne trouve pas un trajet complet.
1315
  local = extract_local(phrase)
1316
  # Petite conversation seulement sans aucun lieu : une demande de trajet gagne
1317
- # toujours (« salam, dama bëgga dem Médina » est un trajet).
 
 
 
 
 
1318
  if not local.get("depart") and not local.get("arrivee"):
1319
  intention = detecter_conversation(phrase)
1320
- if intention is not None:
1321
  return _reponse_conversation(phrase, intention, modele_asr, duree_asr), True
1322
  intent = None
1323
  if local.get("depart") and local.get("arrivee"):
@@ -1329,8 +1341,11 @@ def _pipeline(
1329
  depart, arrivee = intent.get("depart") or "", intent.get("arrivee") or ""
1330
 
1331
  if not depart and not arrivee:
1332
- # Rien compris : ni lieu, ni petite conversation.
1333
- quint = _reponse_conversation(phrase, HORS_SUJET, modele_asr, duree_asr)
 
 
 
1334
  return quint[:4] + (_mention(intent, modele_asr),), False
1335
  if not depart or not arrivee:
1336
  _journal(modele_asr, duree_asr, 0, "lieu_manquant")
 
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,
 
455
  if not phrase or phrase.startswith(ERREUR_ASR):
456
  return False
457
  local = extract_local(phrase)
458
+ if (
459
+ not (local.get("depart") or local.get("arrivee"))
460
+ and detecter_conversation(phrase)
461
+ and not signal_trajet(phrase)
462
+ ):
463
+ # « Salam » seul est compris : inutile de re-transcrire avec l'autre
464
+ # modèle. Mais « Salaam aleekum, damay dem <lieu mal écrit> » est un
465
+ # trajet : l'autre modèle a sa chance d'écrire le lieu correctement.
466
  return True
467
  if not (local.get("depart") and local.get("arrivee")):
468
  return False
 
1321
  # Liberté 6). Le LLM ne sert que si elle ne trouve pas un trajet complet.
1322
  local = extract_local(phrase)
1323
  # Petite conversation seulement sans aucun lieu : une demande de trajet gagne
1324
+ # toujours (« salam, dama bëgga dem Médina » est un trajet). Les usagers
1325
+ # saluent d'abord puis demandent : si la phrase a la forme d'une demande
1326
+ # (« damay dem X », « maa ngi X ») sans lieu reconnu localement, le LLM
1327
+ # passe avant la salutation. Vu en production : « Salaam aleekum, man damay
1328
+ # dem Petersen te maa ngi Ouakam » a reçu trois fois « Maalekum salaam ».
1329
+ intention = None
1330
  if not local.get("depart") and not local.get("arrivee"):
1331
  intention = detecter_conversation(phrase)
1332
+ if intention is not None and not signal_trajet(phrase):
1333
  return _reponse_conversation(phrase, intention, modele_asr, duree_asr), True
1334
  intent = None
1335
  if local.get("depart") and local.get("arrivee"):
 
1341
  depart, arrivee = intent.get("depart") or "", intent.get("arrivee") or ""
1342
 
1343
  if not depart and not arrivee:
1344
+ # Aucun lieu, même pour le LLM. Une salutation reçoit alors sa réponse
1345
+ # habituelle (« Maalekum salaam ! Fan nga bëgga dem ? » redemande le
1346
+ # trajet), sinon « hors sujet ». Dans les deux cas, pas de trajet :
1347
+ # False laisse sa chance à l'autre modèle ASR.
1348
+ quint = _reponse_conversation(phrase, intention or HORS_SUJET, modele_asr, duree_asr)
1349
  return quint[:4] + (_mention(intent, modele_asr),), False
1350
  if not depart or not arrivee:
1351
  _journal(modele_asr, duree_asr, 0, "lieu_manquant")