Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,90 +1,19 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from transformers import
|
| 3 |
-
|
| 4 |
-
# Cargar
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
)
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
- respuestas cálidas, humanas y comprensivas
|
| 21 |
-
|
| 22 |
-
Mensaje del usuario:
|
| 23 |
-
"{mensaje}"
|
| 24 |
-
"""
|
| 25 |
-
resultado = chatbot(prompt)[0]["generated_text"]
|
| 26 |
-
return resultado.strip()
|
| 27 |
-
|
| 28 |
-
# Estilo visual amigable
|
| 29 |
-
custom_css = """
|
| 30 |
-
body {
|
| 31 |
-
background-color: #f8f9fa;
|
| 32 |
-
font-family: 'Segoe UI', sans-serif;
|
| 33 |
-
color: #333;
|
| 34 |
-
}
|
| 35 |
-
.gradio-container {
|
| 36 |
-
max-width: 900px;
|
| 37 |
-
margin: auto;
|
| 38 |
-
padding: 20px;
|
| 39 |
-
}
|
| 40 |
-
textarea, input, select {
|
| 41 |
-
border-radius: 10px !important;
|
| 42 |
-
}
|
| 43 |
-
h1, h2, h3 {
|
| 44 |
-
color: #212529;
|
| 45 |
-
text-align: center;
|
| 46 |
-
}
|
| 47 |
-
"""
|
| 48 |
-
|
| 49 |
-
# Interfaz de Gradio
|
| 50 |
-
with gr.Blocks(css=custom_css) as demo:
|
| 51 |
-
gr.Markdown("""
|
| 52 |
-
# 🩵 FamiIA — Tu Compañera Emocional
|
| 53 |
-
|
| 54 |
-
### Un lugar seguro para familiares de personas con enfermedades raras.
|
| 55 |
-
|
| 56 |
-
Puedes hablar con FamiIA para sentirte escuchado/a, orientado/a o simplemente acompañado/a.
|
| 57 |
-
|
| 58 |
-
---
|
| 59 |
-
|
| 60 |
-
### 💬 Ejemplos:
|
| 61 |
-
|
| 62 |
-
• Estoy agotada por cuidar a mi hijo con Ehlers-Danlos. ¿Qué hago?
|
| 63 |
-
• ¿Cómo puedo explicar esto a sus profesores?
|
| 64 |
-
• ¿Dónde puedo encontrar ayuda para mi bienestar emocional?
|
| 65 |
-
• Solo quiero escribir lo que siento hoy…
|
| 66 |
-
""")
|
| 67 |
-
|
| 68 |
-
enfermedad = gr.Dropdown(
|
| 69 |
-
["Ehlers-Danlos", "Síndrome de Rett", "Fibrosis Quística", "Otra"],
|
| 70 |
-
label="Selecciona la enfermedad",
|
| 71 |
-
value="Ehlers-Danlos"
|
| 72 |
-
)
|
| 73 |
-
|
| 74 |
-
entrada = gr.Textbox(
|
| 75 |
-
placeholder="Escribe cómo te sientes o qué necesitas...",
|
| 76 |
-
label="¿Qué quieres compartir hoy?"
|
| 77 |
-
)
|
| 78 |
-
|
| 79 |
-
salida = gr.Textbox(label="Respuesta de FamiIA")
|
| 80 |
-
|
| 81 |
-
boton = gr.Button("Hablar con FamiIA")
|
| 82 |
-
|
| 83 |
-
def conversar(mensaje, enfermedad):
|
| 84 |
-
if not mensaje.strip():
|
| 85 |
-
return "Por favor, escribe cómo te sientes o qué necesitas preguntar."
|
| 86 |
-
return responder(mensaje, enfermedad)
|
| 87 |
-
|
| 88 |
-
boton.click(fn=conversar, inputs=[entrada, enfermedad], outputs=salida)
|
| 89 |
-
|
| 90 |
-
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 3 |
+
|
| 4 |
+
# Cargar modelo
|
| 5 |
+
model_name = "RayyanAhmed9477/CPU-Compatible-Mental-Health-Model"
|
| 6 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 7 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
| 8 |
+
|
| 9 |
+
def responder(mensaje):
|
| 10 |
+
inputs = tokenizer(mensaje, return_tensors="pt")
|
| 11 |
+
outputs = model.generate(**inputs, max_length=200, pad_token_id=tokenizer.eos_token_id)
|
| 12 |
+
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 13 |
+
|
| 14 |
+
gr.Interface(fn=responder,
|
| 15 |
+
inputs="text",
|
| 16 |
+
outputs="text",
|
| 17 |
+
title="Asistente de Salud Mental (IA)",
|
| 18 |
+
description="IA que acompaña emocionalmente a familiares de pacientes con enfermedades raras."
|
| 19 |
+
).launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|