LoloSemper commited on
Commit
9975c9a
·
verified ·
1 Parent(s): 3f5119f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -10
app.py CHANGED
@@ -1,5 +1,5 @@
1
  # app.py – ES→NI con mejoras en detección morfológica y pipeline
2
- # Versión 2.2 con afinación completa y mejoras finales
3
 
4
  import gradio as gr
5
  import os, csv, re, base64, unicodedata
@@ -478,9 +478,9 @@ TRIDOT = "/"
478
  VISIBLE_PUNCT = set(",.;:…()[]{}\"'«»——""''")
479
  HARD_BOUND = {".",";","—","—",":","(",")","«","»",""",""","'","'"} # límites de cláusula fuertes
480
 
481
- def render_ib_with_tridots(tokens):
482
  res=[]; prev_word=False
483
- for tk in tokens:
484
  is_punct = tk in VISIBLE_PUNCT
485
  if is_punct:
486
  res.append(" "+tk+" "); prev_word=False
@@ -530,9 +530,9 @@ def is_wh_token(t: str) -> bool:
530
  return f in {"que","quien","quienes","cual","cuales","donde","cuando","como","cuanto","cuanta","cuantos","cuantas"}
531
 
532
  # FIX: el detector WH ignora WH dentro de paréntesis y comillas tipográficas
533
- def has_wh_outside_parens(tokens) -> bool:
534
  depth = 0
535
- for tk in tokens:
536
  if tk in {"(", "«", """, "'"}:
537
  depth += 1
538
  elif tk in {")", "»", """, "'"}:
@@ -560,12 +560,12 @@ def rule_a(prev_tok:str, token:str, next_tok:str)->str:
560
  ESTAR_SET={"estoy","estás","está","estamos","estáis","están","estaba","estabas","estábamos","estabais","estaban"}
561
  HABER_SET={"he","has","ha","hemos","habéis","han","había","habías","habíamos","habíais","habían"}
562
 
563
- def detect_tam_with_context(tokens, i, sentence_start=False):
564
- """Versión mejorada con análisis contextual profundo"""
565
  t=toks[i].lower()
566
  prev=toks[i-1].lower() if i>0 else ""
567
  prev2=toks[i-2].lower() if i>1 else ""
568
- nxt=toks[i+1].lower() if i+1<len(tokens) else ""
569
 
570
  # Primero usar detección morfológica mejorada
571
  tag=es_morph_tag(t)
@@ -672,7 +672,7 @@ def normalize_surface_by_pos(ni_surface:str, pos:str) -> str:
672
  return ni_surface
673
 
674
  def translate_sentence(sent:str):
675
- """Pipeline mejorado con detección contextual y manejo de imperativos"""
676
  toks = tokenize_es(normalize_es(sent))
677
 
678
  out_words = [] # palabras en ni (latín)
@@ -719,7 +719,7 @@ def translate_sentence(sent:str):
719
  # pipeline normal
720
  low = t.lower()
721
  prev = toks[i-1].lower() if i>0 else ""
722
- nxt = toks[i+1].lower() if i+1<len(tokens) else ""
723
 
724
  # === DETECCIÓN MEJORADA ===
725
  # Detectar imperativo por contexto de inicio o por clíticos
 
1
  # app.py – ES→NI con mejoras en detección morfológica y pipeline
2
+ # Versión 2.2 con afinación completa y mejoras finales - CORREGIDO
3
 
4
  import gradio as gr
5
  import os, csv, re, base64, unicodedata
 
478
  VISIBLE_PUNCT = set(",.;:…()[]{}\"'«»——""''")
479
  HARD_BOUND = {".",";","—","—",":","(",")","«","»",""",""","'","'"} # límites de cláusula fuertes
480
 
481
+ def render_ib_with_tridots(toks):
482
  res=[]; prev_word=False
483
+ for tk in toks:
484
  is_punct = tk in VISIBLE_PUNCT
485
  if is_punct:
486
  res.append(" "+tk+" "); prev_word=False
 
530
  return f in {"que","quien","quienes","cual","cuales","donde","cuando","como","cuanto","cuanta","cuantos","cuantas"}
531
 
532
  # FIX: el detector WH ignora WH dentro de paréntesis y comillas tipográficas
533
+ def has_wh_outside_parens(toks) -> bool:
534
  depth = 0
535
+ for tk in toks:
536
  if tk in {"(", "«", """, "'"}:
537
  depth += 1
538
  elif tk in {")", "»", """, "'"}:
 
560
  ESTAR_SET={"estoy","estás","está","estamos","estáis","están","estaba","estabas","estábamos","estabais","estaban"}
561
  HABER_SET={"he","has","ha","hemos","habéis","han","había","habías","habíamos","habíais","habían"}
562
 
563
+ def detect_tam_with_context(toks, i, sentence_start=False):
564
+ """Versión mejorada con análisis contextual profundo - CORREGIDO"""
565
  t=toks[i].lower()
566
  prev=toks[i-1].lower() if i>0 else ""
567
  prev2=toks[i-2].lower() if i>1 else ""
568
+ nxt=toks[i+1].lower() if i+1<len(toks) else ""
569
 
570
  # Primero usar detección morfológica mejorada
571
  tag=es_morph_tag(t)
 
672
  return ni_surface
673
 
674
  def translate_sentence(sent:str):
675
+ """Pipeline mejorado con detección contextual y manejo de imperativos - CORREGIDO"""
676
  toks = tokenize_es(normalize_es(sent))
677
 
678
  out_words = [] # palabras en ni (latín)
 
719
  # pipeline normal
720
  low = t.lower()
721
  prev = toks[i-1].lower() if i>0 else ""
722
+ nxt = toks[i+1].lower() if i+1<len(toks) else ""
723
 
724
  # === DETECCIÓN MEJORADA ===
725
  # Detectar imperativo por contexto de inicio o por clíticos