Spaces:
Running
Running
se actualiza herramienta
Browse files
app.py
CHANGED
@@ -45,54 +45,76 @@ class ModelHandler:
|
|
45 |
# Lista de modelos disponibles
|
46 |
model_names = [
|
47 |
"microsoft/Phi-3-mini-4k-instruct",
|
48 |
-
"bigscience/bloomz-560m"
|
49 |
-
"tiiuae/falcon-7b-instruct"
|
50 |
]
|
51 |
|
52 |
# Inicializa el manejador de modelos
|
53 |
model_handler = ModelHandler(model_names, hf_token)
|
54 |
|
55 |
-
#
|
56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
gr.Markdown(
|
58 |
"""
|
59 |
-
## Chatbot Multi-Modelo LLM
|
60 |
-
Este chatbot permite elegir entre m煤ltiples modelos de lenguaje para responder preguntas
|
61 |
-
|
62 |
"""
|
63 |
)
|
64 |
with gr.Row():
|
65 |
model_dropdown = gr.Dropdown(
|
66 |
-
choices=model_names,
|
67 |
value=model_names[0],
|
68 |
-
label="Seleccionar Modelo",
|
69 |
interactive=True
|
70 |
)
|
71 |
with gr.Row():
|
72 |
with gr.Column():
|
73 |
input_text = gr.Textbox(
|
74 |
lines=5,
|
75 |
-
placeholder="Escribe tu
|
76 |
-
label="
|
77 |
)
|
78 |
with gr.Column():
|
79 |
-
|
80 |
lines=5,
|
81 |
label="Respuesta",
|
82 |
-
interactive=False
|
|
|
|
|
|
|
|
|
|
|
|
|
83 |
)
|
84 |
submit_button = gr.Button("Enviar")
|
85 |
|
86 |
# Define la funci贸n de actualizaci贸n
|
87 |
-
def process_input(
|
88 |
-
|
89 |
-
|
|
|
|
|
|
|
|
|
90 |
|
91 |
# Conecta la funci贸n a los componentes
|
92 |
submit_button.click(
|
93 |
fn=process_input,
|
94 |
inputs=[model_dropdown, input_text],
|
95 |
-
outputs=
|
96 |
)
|
97 |
|
98 |
# Lanza la interfaz
|
|
|
45 |
# Lista de modelos disponibles
|
46 |
model_names = [
|
47 |
"microsoft/Phi-3-mini-4k-instruct",
|
48 |
+
"bigscience/bloomz-560m"
|
|
|
49 |
]
|
50 |
|
51 |
# Inicializa el manejador de modelos
|
52 |
model_handler = ModelHandler(model_names, hf_token)
|
53 |
|
54 |
+
# Define la funci贸n para generaci贸n de im谩genes
|
55 |
+
def generate_image(prompt):
|
56 |
+
"""
|
57 |
+
Genera una imagen utilizando un modelo de generaci贸n de im谩genes.
|
58 |
+
"""
|
59 |
+
try:
|
60 |
+
# Aqu铆 puedes usar el modelo de Hugging Face para generaci贸n de im谩genes.
|
61 |
+
# Ejemplo ficticio:
|
62 |
+
image_url = f"https://via.placeholder.com/512.png?text={prompt.replace(' ', '+')}"
|
63 |
+
return image_url
|
64 |
+
except Exception as e:
|
65 |
+
return f"Error al generar la imagen: {e}"
|
66 |
+
|
67 |
+
# Configura la interfaz en Gradio con selecci贸n de modelos y generaci贸n de im谩genes
|
68 |
+
with gr.Blocks(title="Multi-Model LLM Chatbot with Image Generation") as demo:
|
69 |
gr.Markdown(
|
70 |
"""
|
71 |
+
## Chatbot Multi-Modelo LLM con Generaci贸n de Im谩genes
|
72 |
+
Este chatbot permite elegir entre m煤ltiples modelos de lenguaje para responder preguntas o generar im谩genes
|
73 |
+
a partir de descripciones.
|
74 |
"""
|
75 |
)
|
76 |
with gr.Row():
|
77 |
model_dropdown = gr.Dropdown(
|
78 |
+
choices=model_names + ["Generaci贸n de Im谩genes"],
|
79 |
value=model_names[0],
|
80 |
+
label="Seleccionar Acci贸n/Modelo",
|
81 |
interactive=True
|
82 |
)
|
83 |
with gr.Row():
|
84 |
with gr.Column():
|
85 |
input_text = gr.Textbox(
|
86 |
lines=5,
|
87 |
+
placeholder="Escribe tu consulta o descripci贸n para la imagen...",
|
88 |
+
label="Entrada"
|
89 |
)
|
90 |
with gr.Column():
|
91 |
+
output_display = gr.Textbox(
|
92 |
lines=5,
|
93 |
label="Respuesta",
|
94 |
+
interactive=False,
|
95 |
+
visible=False
|
96 |
+
)
|
97 |
+
output_image = gr.Image(
|
98 |
+
label="Imagen Generada",
|
99 |
+
interactive=False,
|
100 |
+
visible=False
|
101 |
)
|
102 |
submit_button = gr.Button("Enviar")
|
103 |
|
104 |
# Define la funci贸n de actualizaci贸n
|
105 |
+
def process_input(selected_action, user_input):
|
106 |
+
if selected_action == "Generaci贸n de Im谩genes":
|
107 |
+
return "", generate_image(user_input), gr.update(visible=True), gr.update(visible=False)
|
108 |
+
else:
|
109 |
+
model_handler.switch_model(selected_action)
|
110 |
+
response = model_handler.generate_response(user_input)
|
111 |
+
return response, None, gr.update(visible=False), gr.update(visible=True)
|
112 |
|
113 |
# Conecta la funci贸n a los componentes
|
114 |
submit_button.click(
|
115 |
fn=process_input,
|
116 |
inputs=[model_dropdown, input_text],
|
117 |
+
outputs=[output_display, output_image, output_image, output_display]
|
118 |
)
|
119 |
|
120 |
# Lanza la interfaz
|