Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,40 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
| 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
def responder(mensaje):
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 3 |
+
import torch
|
| 4 |
|
| 5 |
+
# Nombre del modelo
|
| 6 |
+
model_name = "RayyanAhmed9477/CPU-Compatible-Mental-Health-Model"
|
| 7 |
+
|
| 8 |
+
# Cargar modelo y tokenizador
|
| 9 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 10 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
| 11 |
+
|
| 12 |
+
# Funci贸n de respuesta emocional
|
| 13 |
def responder(mensaje):
|
| 14 |
+
if not mensaje.strip():
|
| 15 |
+
return "馃珎 Estoy aqu铆 para ti. Cu茅ntame lo que sientes."
|
| 16 |
+
|
| 17 |
+
inputs = tokenizer(mensaje, return_tensors="pt")
|
| 18 |
+
|
| 19 |
+
with torch.no_grad():
|
| 20 |
+
outputs = model.generate(
|
| 21 |
+
**inputs,
|
| 22 |
+
max_length=200,
|
| 23 |
+
pad_token_id=tokenizer.eos_token_id,
|
| 24 |
+
do_sample=True,
|
| 25 |
+
temperature=0.7,
|
| 26 |
+
top_p=0.9
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
respuesta = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 30 |
+
return respuesta.strip()
|
| 31 |
|
| 32 |
+
# Interfaz Gradio
|
| 33 |
+
gr.Interface(
|
| 34 |
+
fn=responder,
|
| 35 |
+
inputs=gr.Textbox(label="驴C贸mo te sientes hoy?"),
|
| 36 |
+
outputs=gr.Textbox(label="Respuesta del acompa帽ante emocional"),
|
| 37 |
+
title="馃 Asistente de Apoyo Emocional",
|
| 38 |
+
description="IA emp谩tica dise帽ada para brindar apoyo emocional en momentos dif铆ciles. No sustituye ayuda profesional.",
|
| 39 |
+
theme="soft"
|
| 40 |
+
).launch()
|