Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,8 +2,34 @@ import gradio as gr
|
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
# Cargar un modelo de lenguaje
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
chatbot = pipeline("text-generation", model="gpt2")
|
| 6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
# Funci贸n de respuesta
|
| 8 |
def responder_entrada(user_input):
|
| 9 |
respuesta = chatbot(user_input, max_length=100, num_return_sequences=1)
|
|
|
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
# Cargar un modelo de lenguaje
|
| 5 |
+
from transformers import pipeline
|
| 6 |
+
from datetime import datetime
|
| 7 |
+
|
| 8 |
+
# Crear el chatbot
|
| 9 |
chatbot = pipeline("text-generation", model="gpt2")
|
| 10 |
|
| 11 |
+
def get_response(user_input):
|
| 12 |
+
# Respuestas personalizadas
|
| 13 |
+
if "hola" in user_input.lower():
|
| 14 |
+
return "隆Hola! 驴C贸mo puedo ayudarte hoy?"
|
| 15 |
+
elif "hora" in user_input.lower():
|
| 16 |
+
return f"Son las {datetime.now().strftime('%H:%M')}. 驴Hay algo m谩s en lo que pueda ayudarte?"
|
| 17 |
+
elif "adi贸s" in user_input.lower():
|
| 18 |
+
return "隆Hasta luego! Que tengas un buen d铆a."
|
| 19 |
+
else:
|
| 20 |
+
# Respuesta por defecto usando el modelo
|
| 21 |
+
response = chatbot(user_input, max_length=50)
|
| 22 |
+
return response[0]['generated_text']
|
| 23 |
+
|
| 24 |
+
# Bucle para interactuar con el usuario
|
| 25 |
+
while True:
|
| 26 |
+
user_input = input("T煤: ")
|
| 27 |
+
if user_input.lower() == "salir":
|
| 28 |
+
break
|
| 29 |
+
response = get_response(user_input)
|
| 30 |
+
print("Asistente:", response)
|
| 31 |
+
|
| 32 |
+
|
| 33 |
# Funci贸n de respuesta
|
| 34 |
def responder_entrada(user_input):
|
| 35 |
respuesta = chatbot(user_input, max_length=100, num_return_sequences=1)
|