Spaces:
Sleeping
Sleeping
Update ui.py
Browse files
ui.py
CHANGED
@@ -4,26 +4,26 @@ import gradio as gr
|
|
4 |
from config import SIMILARITY_THRESHOLD_DEFAULT, SYSTEM_PROMPT, MAX_LENGTH_DEFAULT
|
5 |
import os
|
6 |
|
7 |
-
#
|
8 |
def get_theme():
|
9 |
theme = gr.themes.Default(
|
10 |
primary_hue="indigo",
|
11 |
-
# ... (
|
12 |
)
|
13 |
return theme
|
14 |
|
15 |
-
#
|
16 |
def load_images():
|
17 |
image_carousel_data = {
|
18 |
"Análisis Geográfico": [
|
19 |
-
{"image": "images/rId101.png", "description": "
|
20 |
-
{"image": "images/rId105.png", "description": "
|
21 |
],
|
22 |
-
#
|
23 |
}
|
24 |
return image_carousel_data
|
25 |
|
26 |
-
#
|
27 |
def build_interface(process_input, send_preset_question, update_image):
|
28 |
theme = get_theme()
|
29 |
image_carousel_data = load_images()
|
@@ -31,20 +31,25 @@ def build_interface(process_input, send_preset_question, update_image):
|
|
31 |
with gr.Blocks(theme=theme) as demo:
|
32 |
with gr.Row():
|
33 |
with gr.Column(scale=1):
|
34 |
-
#
|
35 |
video = gr.Video(value="video.mp4", label="Video de Introducción")
|
36 |
|
37 |
-
#
|
38 |
gr.Markdown("### Carruseles de Imágenes")
|
39 |
for category, images_list in image_carousel_data.items():
|
40 |
gr.Markdown(f"#### {category}")
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
|
|
|
|
|
|
|
|
|
|
46 |
|
47 |
-
#
|
48 |
download_button = gr.File(label="Descargar Informe", value="Reporte.pdf")
|
49 |
|
50 |
# Chatbot
|
@@ -55,7 +60,7 @@ def build_interface(process_input, send_preset_question, update_image):
|
|
55 |
submit_button = gr.Button("Enviar")
|
56 |
chatbot_history = gr.State(value=[])
|
57 |
|
58 |
-
#
|
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",
|
@@ -77,22 +82,19 @@ def build_interface(process_input, send_preset_question, update_image):
|
|
77 |
image_url = gr.State(value=None)
|
78 |
image_output = gr.Image(label="Imagen asociada")
|
79 |
|
80 |
-
|
81 |
-
|
|
|
|
|
|
|
|
|
82 |
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
|
|
87 |
)
|
88 |
-
|
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
|
|
|
4 |
from config import SIMILARITY_THRESHOLD_DEFAULT, SYSTEM_PROMPT, MAX_LENGTH_DEFAULT
|
5 |
import os
|
6 |
|
7 |
+
# Define the theme (you can keep your custom theme)
|
8 |
def get_theme():
|
9 |
theme = gr.themes.Default(
|
10 |
primary_hue="indigo",
|
11 |
+
# ... (rest of your theme configuration)
|
12 |
)
|
13 |
return theme
|
14 |
|
15 |
+
# Load images and descriptions
|
16 |
def load_images():
|
17 |
image_carousel_data = {
|
18 |
"Análisis Geográfico": [
|
19 |
+
{"image": "images/rId101.png", "description": "📊 Lima (150101) has the highest number of records..."},
|
20 |
+
{"image": "images/rId105.png", "description": "🏥 Level 3 establishments are the most represented..."},
|
21 |
],
|
22 |
+
# Add more categories and images as needed
|
23 |
}
|
24 |
return image_carousel_data
|
25 |
|
26 |
+
# Build the interface
|
27 |
def build_interface(process_input, send_preset_question, update_image):
|
28 |
theme = get_theme()
|
29 |
image_carousel_data = load_images()
|
|
|
31 |
with gr.Blocks(theme=theme) as demo:
|
32 |
with gr.Row():
|
33 |
with gr.Column(scale=1):
|
34 |
+
# Add the video
|
35 |
video = gr.Video(value="video.mp4", label="Video de Introducción")
|
36 |
|
37 |
+
# Image Galleries
|
38 |
gr.Markdown("### Carruseles de Imágenes")
|
39 |
for category, images_list in image_carousel_data.items():
|
40 |
gr.Markdown(f"#### {category}")
|
41 |
+
# Use gr.Gallery instead of gr.Carousel
|
42 |
+
gallery_items = []
|
43 |
+
for item in images_list:
|
44 |
+
gallery_items.append((item["image"], item["description"]))
|
45 |
+
gr.Gallery(
|
46 |
+
value=gallery_items,
|
47 |
+
label=category,
|
48 |
+
show_label=False,
|
49 |
+
elem_id=None
|
50 |
+
)
|
51 |
|
52 |
+
# Download button
|
53 |
download_button = gr.File(label="Descargar Informe", value="Reporte.pdf")
|
54 |
|
55 |
# Chatbot
|
|
|
60 |
submit_button = gr.Button("Enviar")
|
61 |
chatbot_history = gr.State(value=[])
|
62 |
|
63 |
+
# Add selection options
|
64 |
selection = gr.Radio(
|
65 |
["Solo Búsqueda Vectorial", "Solo Yi-Coder", "Ambos (basado en umbral de similitud)"],
|
66 |
label="Seleccione el modo de búsqueda",
|
|
|
82 |
image_url = gr.State(value=None)
|
83 |
image_output = gr.Image(label="Imagen asociada")
|
84 |
|
85 |
+
# Define processing functions
|
86 |
+
def on_submit(message, history, selected_option, similarity_threshold, system_prompt, max_length):
|
87 |
+
history, new_history, image = process_input(
|
88 |
+
message, history, selected_option, similarity_threshold, system_prompt, max_length
|
89 |
+
)
|
90 |
+
return history, new_history, image
|
91 |
|
92 |
+
# Configure click events for the chatbot
|
93 |
+
submit_button.click(
|
94 |
+
on_submit,
|
95 |
+
inputs=[chatbot_input, chatbot_history, selection, similarity_threshold_slider, system_prompt_input, max_length_slider],
|
96 |
+
outputs=[chatbot_output, chatbot_history, image_url]
|
97 |
)
|
98 |
+
image_url.change(fn=update_image, inputs=image_url, outputs=image_output)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
99 |
|
100 |
return demo
|