Spaces:
Sleeping
Sleeping
# ui.py | |
import gradio as gr | |
from config import SIMILARITY_THRESHOLD_DEFAULT, SYSTEM_PROMPT, MAX_LENGTH_DEFAULT | |
import os | |
# Definir el tema (puedes mantener tu tema personalizado) | |
def get_theme(): | |
theme = gr.themes.Default( | |
primary_hue="indigo", | |
# ... (resto de la configuración de tu tema) | |
) | |
return theme | |
# Cargar imágenes y descripciones | |
def load_images(): | |
image_carousel_data = { | |
"Análisis Geográfico": [ | |
{"image": "images/rId101.png", "description": "Descripción de la imagen 1"}, | |
{"image": "images/rId105.png", "description": "Descripción de la imagen 2"}, | |
], | |
# Añade más categorías y sus imágenes según necesites | |
} | |
return image_carousel_data | |
# Construir la interfaz | |
def build_interface(process_input, send_preset_question, update_image): | |
theme = get_theme() | |
image_carousel_data = load_images() | |
with gr.Blocks(theme=theme) as demo: | |
with gr.Row(): | |
with gr.Column(scale=1): | |
# Agregar el video | |
video = gr.Video(value="video.mp4", label="Video de Introducción") | |
# Carruseles de imágenes | |
gr.Markdown("### Carruseles de Imágenes") | |
for category, images_list in image_carousel_data.items(): | |
gr.Markdown(f"#### {category}") | |
with gr.Carousel(): | |
for item in images_list: | |
with gr.Card(): | |
gr.Image(value=item["image"]) | |
gr.Markdown(item["description"]) | |
# Botón de descarga | |
download_button = gr.File(label="Descargar Informe", value="Reporte.pdf") | |
# Chatbot | |
with gr.Row(): | |
with gr.Column(scale=1): | |
chatbot_output = gr.Chatbot(label="ChatBot", elem_id="chatbot_output") | |
chatbot_input = gr.Textbox(label="Tu mensaje", elem_id="chatbot_input") | |
submit_button = gr.Button("Enviar") | |
chatbot_history = gr.State(value=[]) | |
# Añadir opciones de selección | |
selection = gr.Radio( | |
["Solo Búsqueda Vectorial", "Solo Yi-Coder", "Ambos (basado en umbral de similitud)"], | |
label="Seleccione el modo de búsqueda", | |
value="Ambos (basado en umbral de similitud)" | |
) | |
similarity_threshold_slider = gr.Slider( | |
minimum=0.0, maximum=1.0, value=SIMILARITY_THRESHOLD_DEFAULT, step=0.01, | |
label="Umbral de similitud (solo para 'Ambos')" | |
) | |
max_length_slider = gr.Slider( | |
minimum=1, maximum=1000, value=MAX_LENGTH_DEFAULT, | |
label="Longitud máxima de tokens (solo para Yi-Coder)" | |
) | |
system_prompt_input = gr.Textbox( | |
label="Instrucción del sistema", value=SYSTEM_PROMPT, lines=2 | |
) | |
with gr.Column(scale=1): | |
image_url = gr.State(value=None) | |
image_output = gr.Image(label="Imagen asociada") | |
# Aquí puedes incluir tus botones y categorías | |
# ... | |
# Definir las funciones de procesamiento | |
def on_submit(message, history, selected_option, similarity_threshold, system_prompt, max_length): | |
history, new_history, image = process_input( | |
message, history, selected_option, similarity_threshold, system_prompt, max_length | |
) | |
return history, new_history, image | |
# Configurar eventos de clic para el chatbot | |
submit_button.click( | |
on_submit, | |
inputs=[chatbot_input, chatbot_history, selection, similarity_threshold_slider, system_prompt_input, max_length_slider], | |
outputs=[chatbot_output, chatbot_history, image_url] | |
) | |
image_url.change(fn=update_image, inputs=image_url, outputs=image_output) | |
return demo | |