Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -11,6 +11,7 @@ from transformers import (
|
|
| 11 |
TrainingArguments,
|
| 12 |
Trainer,
|
| 13 |
pipeline,
|
|
|
|
| 14 |
)
|
| 15 |
import evaluate # type: ignore
|
| 16 |
from huggingface_hub import login
|
|
@@ -48,7 +49,7 @@ def detect_language(text):
|
|
| 48 |
return "en" # Si no se puede detectar, se asume inglés
|
| 49 |
|
| 50 |
# Generación de texto (si se solicita un cuento, por ejemplo)
|
| 51 |
-
def generate_text(prompt, max_length=
|
| 52 |
output = generator(prompt, max_length=int(max_length), num_return_sequences=1)[0]["generated_text"]
|
| 53 |
return output
|
| 54 |
|
|
@@ -82,11 +83,11 @@ def process_input(user_input):
|
|
| 82 |
elif "cuento" in user_input.lower():
|
| 83 |
# Si el usuario solicita un cuento
|
| 84 |
prompt = "Había una vez, en un reino lejano..."
|
| 85 |
-
return generate_text(prompt, max_length=
|
| 86 |
elif "emoción" in user_input.lower():
|
| 87 |
# Si es una solicitud de apoyo emocional
|
| 88 |
context = "Dom: Psicología | Estilo: Apoyo emocional. ¿Cómo te sientes hoy?"
|
| 89 |
-
return generate_text(context + " Estoy aquí para apoyarte", max_length=
|
| 90 |
else:
|
| 91 |
return "No entiendo la solicitud, por favor intenta preguntar algo más específico."
|
| 92 |
|
|
|
|
| 11 |
TrainingArguments,
|
| 12 |
Trainer,
|
| 13 |
pipeline,
|
| 14 |
+
AutoModelForQuestionAnswering,
|
| 15 |
)
|
| 16 |
import evaluate # type: ignore
|
| 17 |
from huggingface_hub import login
|
|
|
|
| 49 |
return "en" # Si no se puede detectar, se asume inglés
|
| 50 |
|
| 51 |
# Generación de texto (si se solicita un cuento, por ejemplo)
|
| 52 |
+
def generate_text(prompt, max_length=2048):
|
| 53 |
output = generator(prompt, max_length=int(max_length), num_return_sequences=1)[0]["generated_text"]
|
| 54 |
return output
|
| 55 |
|
|
|
|
| 83 |
elif "cuento" in user_input.lower():
|
| 84 |
# Si el usuario solicita un cuento
|
| 85 |
prompt = "Había una vez, en un reino lejano..."
|
| 86 |
+
return generate_text(prompt, max_length=500)
|
| 87 |
elif "emoción" in user_input.lower():
|
| 88 |
# Si es una solicitud de apoyo emocional
|
| 89 |
context = "Dom: Psicología | Estilo: Apoyo emocional. ¿Cómo te sientes hoy?"
|
| 90 |
+
return generate_text(context + " Estoy aquí para apoyarte", max_length=2048)
|
| 91 |
else:
|
| 92 |
return "No entiendo la solicitud, por favor intenta preguntar algo más específico."
|
| 93 |
|