Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,31 +1,44 @@
|
|
1 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
from transformers import pipeline
|
3 |
import gradio as gr
|
4 |
|
5 |
-
#
|
6 |
chatbot = pipeline(
|
7 |
-
"text-generation",
|
8 |
-
model="
|
9 |
-
max_length=
|
10 |
-
pad_token_id=50256,
|
11 |
-
temperature=0.
|
12 |
-
top_k=50
|
13 |
)
|
14 |
|
15 |
-
#
|
16 |
def responder(pregunta):
|
17 |
-
respuesta
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
-
#
|
21 |
-
|
22 |
-
fn=responder,
|
23 |
-
inputs="text",
|
24 |
-
outputs="text",
|
25 |
-
title="Chatbot
|
26 |
-
description="Hazme
|
27 |
)
|
28 |
|
29 |
-
#
|
30 |
if __name__ == "__main__":
|
31 |
-
|
|
|
1 |
+
# Primero, instalamos las bibliotecas necesarias
|
2 |
+
# NOTA: No uses el signo "!" en Hugging Face, ya que eso genera un error.
|
3 |
+
# Si usas Hugging Face Spaces, las dependencias se instalan desde el archivo requirements.txt.
|
4 |
+
# Aseg煤rate de tener este archivo con las l铆neas:
|
5 |
+
# transformers
|
6 |
+
# gradio
|
7 |
+
# torch
|
8 |
+
|
9 |
from transformers import pipeline
|
10 |
import gradio as gr
|
11 |
|
12 |
+
# Configuraci贸n del modelo de lenguaje: distilgpt2 para respuestas r谩pidas y concisas
|
13 |
chatbot = pipeline(
|
14 |
+
"text-generation",
|
15 |
+
model="distilgpt2", # Usa "distilgpt2" para respuestas r谩pidas
|
16 |
+
max_length=50,
|
17 |
+
pad_token_id=50256,
|
18 |
+
temperature=0.5, # Baja aleatoriedad para respuestas m谩s coherentes
|
19 |
+
top_k=50
|
20 |
)
|
21 |
|
22 |
+
# Definimos la funci贸n para manejar la pregunta y limpiar la respuesta
|
23 |
def responder(pregunta):
|
24 |
+
# Generamos la respuesta con el modelo
|
25 |
+
respuesta = chatbot(pregunta, max_length=50, num_return_sequences=1)
|
26 |
+
respuesta_texto = respuesta[0]['generated_text']
|
27 |
+
|
28 |
+
# Limpiamos la respuesta para eliminar repeticiones
|
29 |
+
respuesta_texto = respuesta_texto.split(".")[0] + "."
|
30 |
+
|
31 |
+
return respuesta_texto
|
32 |
|
33 |
+
# Interfaz gr谩fica de usuario usando Gradio
|
34 |
+
iface = gr.Interface(
|
35 |
+
fn=responder,
|
36 |
+
inputs="text",
|
37 |
+
outputs="text",
|
38 |
+
title="Chatbot AI",
|
39 |
+
description="Hazme cualquier pregunta, y te responder茅 como un asistente de IA."
|
40 |
)
|
41 |
|
42 |
+
# Ejecutar la aplicaci贸n
|
43 |
if __name__ == "__main__":
|
44 |
+
iface.launch()
|