Malaji71 commited on
Commit
707bd20
·
verified ·
1 Parent(s): b40fc4b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -6
app.py CHANGED
@@ -38,10 +38,31 @@ class LlamaRefiner:
38
  return text
39
  try:
40
  result = self.translator(text, max_length=250, clean_up_tokenization_spaces=True)
41
- return result[0]['translation_text'].strip()
42
  except Exception as e:
43
  logger.warning(f"Traducción local fallida: {e}. Usando texto original.")
44
- return text
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
 
46
  def retrieve_similar_examples(self, user_prompt_en: str, category: str = "auto", k: int = 6) -> list:
47
  if not self.agent.is_ready:
@@ -85,9 +106,9 @@ class LlamaRefiner:
85
  user_prompt_en = self.translate_to_english(user_prompt)
86
  examples = self.retrieve_similar_examples(user_prompt_en, category=category, k=6)
87
 
88
- # ✅ Usar solo enriquecimiento local (más fiable y coherente)
89
  enhanced_prompt, _ = self.agent.enhance_prompt(user_prompt_en, category=category)
90
- return enhanced_prompt.strip(), "✨ Enriquecimiento semántico por frases coherentes", examples
91
 
92
  class SDXLGenerator:
93
  def __init__(self):
@@ -124,7 +145,7 @@ def create_interface():
124
  return "", "", "Prompt vacío."
125
  if refiner is None:
126
  return "", "", "Servicios no disponibles."
127
- progress(0.2, desc="🌍 Traduciendo y enriqueciendo...")
128
  category_map = {
129
  "Automática": "auto",
130
  "Entidad": "entity",
@@ -195,7 +216,7 @@ def create_interface():
195
  label="Prompt refinado (inglés)",
196
  interactive=False,
197
  lines=3,
198
- elem_classes=["gr-copyable"] # ← activa el botón de copia en Gradio
199
  )
200
  image_out = gr.Image(label="Imagen", type="filepath", height=450)
201
  examples_out = gr.Textbox(label="Ejemplos del dataset (para análisis)", interactive=False, lines=6)
 
38
  return text
39
  try:
40
  result = self.translator(text, max_length=250, clean_up_tokenization_spaces=True)
41
+ raw_translation = result[0]['translation_text'].strip()
42
  except Exception as e:
43
  logger.warning(f"Traducción local fallida: {e}. Usando texto original.")
44
+ raw_translation = text
45
+
46
+ user_text_lower = text.lower()
47
+ output = raw_translation
48
+
49
+ if any(kw in user_text_lower for kw in ["llamas", "ardiendo", "quem", "incendi", "fuego"]):
50
+ output = output.replace("fiery", "on fire")
51
+ if not any(term in output.lower() for term in ["on fire", "burning", "in flames", "ablaze", "aflame"]):
52
+ output = output + " on fire"
53
+
54
+ if any(kw in user_text_lower for kw in ["oro", "dorado"]):
55
+ if "golden" not in output.lower() and "gold" not in output.lower():
56
+ if any(w in output.lower() for w in ["statue", "sculpture", "figure"]):
57
+ output = output + " made of gold"
58
+ else:
59
+ output = output + " golden"
60
+
61
+ if any(kw in user_text_lower for kw in ["congelado", "hielo", "helado", "ice"]):
62
+ if not any(term in output.lower() for term in ["frozen", "ice", "icy"]):
63
+ output = output + " frozen"
64
+
65
+ return output.strip()
66
 
67
  def retrieve_similar_examples(self, user_prompt_en: str, category: str = "auto", k: int = 6) -> list:
68
  if not self.agent.is_ready:
 
106
  user_prompt_en = self.translate_to_english(user_prompt)
107
  examples = self.retrieve_similar_examples(user_prompt_en, category=category, k=6)
108
 
109
+ # ✅ Usar SOLO enriquecimiento local (como en la versión que funcionaba)
110
  enhanced_prompt, _ = self.agent.enhance_prompt(user_prompt_en, category=category)
111
+ return enhanced_prompt.strip(), "✨ Enriquecimiento semántico local", examples
112
 
113
  class SDXLGenerator:
114
  def __init__(self):
 
145
  return "", "", "Prompt vacío."
146
  if refiner is None:
147
  return "", "", "Servicios no disponibles."
148
+ progress(0.2, desc="🌍 Traduciendo...")
149
  category_map = {
150
  "Automática": "auto",
151
  "Entidad": "entity",
 
216
  label="Prompt refinado (inglés)",
217
  interactive=False,
218
  lines=3,
219
+ elem_classes=["gr-copyable"]
220
  )
221
  image_out = gr.Image(label="Imagen", type="filepath", height=450)
222
  examples_out = gr.Textbox(label="Ejemplos del dataset (para análisis)", interactive=False, lines=6)