Spaces:
Runtime error
Runtime error
Create ui.py
Browse files
ui.py
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# ui.py
|
| 2 |
+
|
| 3 |
+
import gradio as gr
|
| 4 |
+
from config import SIMILARITY_THRESHOLD_DEFAULT, SYSTEM_PROMPT, MAX_LENGTH_DEFAULT
|
| 5 |
+
import os
|
| 6 |
+
|
| 7 |
+
# Definir el tema (puedes mantener tu tema personalizado)
|
| 8 |
+
def get_theme():
|
| 9 |
+
theme = gr.themes.Default(
|
| 10 |
+
primary_hue="indigo",
|
| 11 |
+
# ... (resto de la configuración de tu tema)
|
| 12 |
+
)
|
| 13 |
+
return theme
|
| 14 |
+
|
| 15 |
+
# Cargar imágenes y descripciones
|
| 16 |
+
def load_images():
|
| 17 |
+
image_carousel_data = {
|
| 18 |
+
"Análisis Geográfico": [
|
| 19 |
+
{"image": "images/rId101.png", "description": "Descripción de la imagen 1"},
|
| 20 |
+
{"image": "images/rId105.png", "description": "Descripción de la imagen 2"},
|
| 21 |
+
],
|
| 22 |
+
# Añade más categorías y sus imágenes según necesites
|
| 23 |
+
}
|
| 24 |
+
return image_carousel_data
|
| 25 |
+
|
| 26 |
+
# Construir la interfaz
|
| 27 |
+
def build_interface(process_input, send_preset_question, update_image):
|
| 28 |
+
theme = get_theme()
|
| 29 |
+
image_carousel_data = load_images()
|
| 30 |
+
|
| 31 |
+
with gr.Blocks(theme=theme) as demo:
|
| 32 |
+
with gr.Row():
|
| 33 |
+
with gr.Column(scale=1):
|
| 34 |
+
# Agregar el video
|
| 35 |
+
video = gr.Video(value="video.mp4", label="Video de Introducción")
|
| 36 |
+
|
| 37 |
+
# Carruseles de imágenes
|
| 38 |
+
gr.Markdown("### Carruseles de Imágenes")
|
| 39 |
+
for category, images_list in image_carousel_data.items():
|
| 40 |
+
gr.Markdown(f"#### {category}")
|
| 41 |
+
with gr.Carousel():
|
| 42 |
+
for item in images_list:
|
| 43 |
+
with gr.Card():
|
| 44 |
+
gr.Image(value=item["image"])
|
| 45 |
+
gr.Markdown(item["description"])
|
| 46 |
+
|
| 47 |
+
# Botón de descarga
|
| 48 |
+
download_button = gr.File(label="Descargar Informe", value="Reporte.pdf")
|
| 49 |
+
|
| 50 |
+
# Chatbot
|
| 51 |
+
with gr.Row():
|
| 52 |
+
with gr.Column(scale=1):
|
| 53 |
+
chatbot_output = gr.Chatbot(label="ChatBot", elem_id="chatbot_output")
|
| 54 |
+
chatbot_input = gr.Textbox(label="Tu mensaje", elem_id="chatbot_input")
|
| 55 |
+
submit_button = gr.Button("Enviar")
|
| 56 |
+
chatbot_history = gr.State(value=[])
|
| 57 |
+
|
| 58 |
+
# Añadir opciones de selección
|
| 59 |
+
selection = gr.Radio(
|
| 60 |
+
["Solo Búsqueda Vectorial", "Solo Yi-Coder", "Ambos (basado en umbral de similitud)"],
|
| 61 |
+
label="Seleccione el modo de búsqueda",
|
| 62 |
+
value="Ambos (basado en umbral de similitud)"
|
| 63 |
+
)
|
| 64 |
+
similarity_threshold_slider = gr.Slider(
|
| 65 |
+
minimum=0.0, maximum=1.0, value=SIMILARITY_THRESHOLD_DEFAULT, step=0.01,
|
| 66 |
+
label="Umbral de similitud (solo para 'Ambos')"
|
| 67 |
+
)
|
| 68 |
+
max_length_slider = gr.Slider(
|
| 69 |
+
minimum=1, maximum=1000, value=MAX_LENGTH_DEFAULT,
|
| 70 |
+
label="Longitud máxima de tokens (solo para Yi-Coder)"
|
| 71 |
+
)
|
| 72 |
+
system_prompt_input = gr.Textbox(
|
| 73 |
+
label="Instrucción del sistema", value=SYSTEM_PROMPT, lines=2
|
| 74 |
+
)
|
| 75 |
+
|
| 76 |
+
with gr.Column(scale=1):
|
| 77 |
+
image_url = gr.State(value=None)
|
| 78 |
+
image_output = gr.Image(label="Imagen asociada")
|
| 79 |
+
|
| 80 |
+
# Aquí puedes incluir tus botones y categorías
|
| 81 |
+
# ...
|
| 82 |
+
|
| 83 |
+
# Definir las funciones de procesamiento
|
| 84 |
+
def on_submit(message, history, selected_option, similarity_threshold, system_prompt, max_length):
|
| 85 |
+
history, new_history, image = process_input(
|
| 86 |
+
message, history, selected_option, similarity_threshold, system_prompt, max_length
|
| 87 |
+
)
|
| 88 |
+
return history, new_history, image
|
| 89 |
+
|
| 90 |
+
# Configurar eventos de clic para el chatbot
|
| 91 |
+
submit_button.click(
|
| 92 |
+
on_submit,
|
| 93 |
+
inputs=[chatbot_input, chatbot_history, selection, similarity_threshold_slider, system_prompt_input, max_length_slider],
|
| 94 |
+
outputs=[chatbot_output, chatbot_history, image_url]
|
| 95 |
+
)
|
| 96 |
+
image_url.change(fn=update_image, inputs=image_url, outputs=image_output)
|
| 97 |
+
|
| 98 |
+
return demo
|