Spaces:
Sleeping
Sleeping
Delete app.py
Browse files
app.py
DELETED
@@ -1,39 +0,0 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
from transformers import AutoModelForCausalLM, AutoTokenizer
|
3 |
-
|
4 |
-
# Cargar el modelo y tokenizador de Hugging Face
|
5 |
-
model_name = "microsoft/DialoGPT-medium" # Puedes cambiar este modelo
|
6 |
-
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
7 |
-
model = AutoModelForCausalLM.from_pretrained(model_name)
|
8 |
-
|
9 |
-
# Historial de conversaci贸n
|
10 |
-
chat_history_ids = None
|
11 |
-
|
12 |
-
# Funci贸n para procesar los mensajes del usuario
|
13 |
-
def chatbot(input_text, history=[]):
|
14 |
-
global chat_history_ids
|
15 |
-
new_input_ids = tokenizer.encode(input_text + tokenizer.eos_token, return_tensors="pt")
|
16 |
-
|
17 |
-
# Generar respuesta
|
18 |
-
bot_output = model.generate(
|
19 |
-
new_input_ids,
|
20 |
-
max_length=1000,
|
21 |
-
pad_token_id=tokenizer.eos_token_id
|
22 |
-
)
|
23 |
-
response = tokenizer.decode(bot_output[:, new_input_ids.shape[-1]:][0], skip_special_tokens=True)
|
24 |
-
|
25 |
-
# Actualizar historial
|
26 |
-
history.append((input_text, response))
|
27 |
-
return history, history
|
28 |
-
|
29 |
-
# Configurar la interfaz de Gradio
|
30 |
-
iface = gr.Interface(
|
31 |
-
fn=chatbot,
|
32 |
-
inputs=["text", "state"],
|
33 |
-
outputs=["chatbot", "state"],
|
34 |
-
title="Neuronpyme Chatbot",
|
35 |
-
description="Habla con nuestro chatbot experto en inteligencia artificial para PYMEs.",
|
36 |
-
theme="default"
|
37 |
-
)
|
38 |
-
|
39 |
-
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|