Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -39,20 +39,23 @@ MODEL_REPO = "TeszenAI/MTP-3.1.1"
|
|
| 39 |
# ======================
|
| 40 |
|
| 41 |
def truncate_greeting_response(text: str) -> str:
|
| 42 |
-
"""
|
|
|
|
|
|
|
|
|
|
| 43 |
if not text:
|
| 44 |
return text
|
| 45 |
|
| 46 |
-
# Buscar el primer
|
| 47 |
-
|
| 48 |
-
end_match = re.search(end_pattern, text)
|
| 49 |
|
| 50 |
if end_match:
|
|
|
|
| 51 |
end_pos = end_match.end()
|
| 52 |
truncated = text[:end_pos].strip()
|
| 53 |
return truncated
|
| 54 |
|
| 55 |
-
# Si no hay
|
| 56 |
if len(text) > 80:
|
| 57 |
return text[:80] + "..."
|
| 58 |
return text
|
|
@@ -87,13 +90,13 @@ def clean_response(text: str, user_input: str = "") -> str:
|
|
| 87 |
is_greeting = user_input.lower().strip() in ["hola", "hola!", "hola.", "buenas", "saludos", "hola?"]
|
| 88 |
|
| 89 |
if is_greeting and text:
|
| 90 |
-
# Para saludos, truncar
|
| 91 |
-
punct_match = re.search(r'
|
| 92 |
if punct_match:
|
| 93 |
text = text[:punct_match.end()].strip()
|
| 94 |
else:
|
| 95 |
-
# Si no hay
|
| 96 |
-
first_sentence = text.split('.')[0].
|
| 97 |
if len(first_sentence) > 5:
|
| 98 |
text = first_sentence
|
| 99 |
elif len(text) > 60:
|
|
@@ -101,7 +104,6 @@ def clean_response(text: str, user_input: str = "") -> str:
|
|
| 101 |
|
| 102 |
# Si la respuesta es muy corta o vacía
|
| 103 |
if len(text.strip()) < 5:
|
| 104 |
-
# Respuestas por defecto según el tipo de saludo
|
| 105 |
if is_greeting:
|
| 106 |
return "¡Hola! ¿En qué puedo ayudarte?"
|
| 107 |
return "Lo siento, no pude generar una respuesta clara. ¿Podrías reformular tu pregunta?"
|
|
@@ -436,9 +438,8 @@ async def generate(req: PromptRequest):
|
|
| 436 |
|
| 437 |
except Exception as e:
|
| 438 |
print(f"❌ Error durante generación: {e}")
|
| 439 |
-
# Respuesta de fallback
|
| 440 |
if is_greeting:
|
| 441 |
-
fallback = "¡Hola! ¿
|
| 442 |
else:
|
| 443 |
fallback = "Lo siento, ocurrió un error al procesar tu solicitud."
|
| 444 |
return {
|
|
|
|
| 39 |
# ======================
|
| 40 |
|
| 41 |
def truncate_greeting_response(text: str) -> str:
|
| 42 |
+
"""
|
| 43 |
+
Para respuestas de saludo, trunca SOLO en el primer PUNTO (.)
|
| 44 |
+
No usa signos de exclamación o interrogación.
|
| 45 |
+
"""
|
| 46 |
if not text:
|
| 47 |
return text
|
| 48 |
|
| 49 |
+
# Buscar el primer PUNTO (.)
|
| 50 |
+
end_match = re.search(r'\.', text)
|
|
|
|
| 51 |
|
| 52 |
if end_match:
|
| 53 |
+
# Cortar justo después del punto
|
| 54 |
end_pos = end_match.end()
|
| 55 |
truncated = text[:end_pos].strip()
|
| 56 |
return truncated
|
| 57 |
|
| 58 |
+
# Si no hay punto, devolver solo primeras 80 caracteres
|
| 59 |
if len(text) > 80:
|
| 60 |
return text[:80] + "..."
|
| 61 |
return text
|
|
|
|
| 90 |
is_greeting = user_input.lower().strip() in ["hola", "hola!", "hola.", "buenas", "saludos", "hola?"]
|
| 91 |
|
| 92 |
if is_greeting and text:
|
| 93 |
+
# Para saludos, truncar SOLO en el primer PUNTO (.)
|
| 94 |
+
punct_match = re.search(r'\.', text)
|
| 95 |
if punct_match:
|
| 96 |
text = text[:punct_match.end()].strip()
|
| 97 |
else:
|
| 98 |
+
# Si no hay punto, tomar solo la primera oración o 60 caracteres
|
| 99 |
+
first_sentence = text.split('.')[0].strip()
|
| 100 |
if len(first_sentence) > 5:
|
| 101 |
text = first_sentence
|
| 102 |
elif len(text) > 60:
|
|
|
|
| 104 |
|
| 105 |
# Si la respuesta es muy corta o vacía
|
| 106 |
if len(text.strip()) < 5:
|
|
|
|
| 107 |
if is_greeting:
|
| 108 |
return "¡Hola! ¿En qué puedo ayudarte?"
|
| 109 |
return "Lo siento, no pude generar una respuesta clara. ¿Podrías reformular tu pregunta?"
|
|
|
|
| 438 |
|
| 439 |
except Exception as e:
|
| 440 |
print(f"❌ Error durante generación: {e}")
|
|
|
|
| 441 |
if is_greeting:
|
| 442 |
+
fallback = "¡Hola! ¿En qué puedo ayudarte?"
|
| 443 |
else:
|
| 444 |
fallback = "Lo siento, ocurrió un error al procesar tu solicitud."
|
| 445 |
return {
|