Spaces:
Running
on
Zero
Running
on
Zero
Update ui.py
Browse files
ui.py
CHANGED
@@ -1,16 +1,5 @@
|
|
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 |
-
# 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():
|
@@ -19,82 +8,81 @@ def load_images():
|
|
19 |
{"image": "images/rld1.png", "description": "NASA"},
|
20 |
{"image": "images/rld2.png", "description": "NASA"},
|
21 |
],
|
22 |
-
#
|
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()
|
30 |
|
31 |
-
with gr.Blocks(theme='upsatwal/mlsc_tiet') as demo:
|
32 |
-
|
33 |
-
|
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 |
-
gallery_items =
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
value=gallery_items,
|
47 |
-
label=category,
|
48 |
-
show_label=False,
|
49 |
-
elem_id=None
|
50 |
-
)
|
51 |
|
52 |
-
#
|
53 |
-
|
|
|
|
|
|
|
54 |
|
55 |
-
#
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
label="Seleccione el modo de búsqueda",
|
67 |
-
value="Ambos (basado en umbral de similitud)"
|
68 |
-
)
|
69 |
-
similarity_threshold_slider = gr.Slider(
|
70 |
-
minimum=0.0, maximum=1.0, value=SIMILARITY_THRESHOLD_DEFAULT, step=0.01,
|
71 |
-
label="Umbral de similitud (solo para 'Ambos')"
|
72 |
-
)
|
73 |
-
max_length_slider = gr.Slider(
|
74 |
-
minimum=1, maximum=1000, value=MAX_LENGTH_DEFAULT,
|
75 |
-
label="Longitud máxima de tokens (solo para Yi-Coder)"
|
76 |
-
)
|
77 |
-
system_prompt_input = gr.Textbox(
|
78 |
-
label="Instrucción del sistema", value=SYSTEM_PROMPT, lines=2
|
79 |
-
)
|
80 |
|
81 |
-
|
82 |
-
|
83 |
-
|
|
|
|
|
|
|
84 |
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
|
|
|
|
|
|
91 |
|
92 |
-
|
93 |
-
|
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
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
from config import SIMILARITY_THRESHOLD_DEFAULT, SYSTEM_PROMPT, MAX_LENGTH_DEFAULT
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
# Load images and descriptions
|
5 |
def load_images():
|
|
|
8 |
{"image": "images/rld1.png", "description": "NASA"},
|
9 |
{"image": "images/rld2.png", "description": "NASA"},
|
10 |
],
|
11 |
+
# Agrega más categorías y imágenes según sea necesario
|
12 |
}
|
13 |
return image_carousel_data
|
14 |
|
15 |
# Build the interface
|
16 |
def build_interface(process_input, send_preset_question, update_image):
|
|
|
17 |
image_carousel_data = load_images()
|
18 |
|
19 |
+
with gr.Blocks(theme='upsatwal/mlsc_tiet', elem_id="main-container") as demo:
|
20 |
+
# Ajustar una fila contenedora con escala global para centrar todo
|
21 |
+
with gr.Row(elem_id="center-row", scale=0.8):
|
22 |
+
with gr.Column(scale=0.8): # Columna única para centrar el contenido
|
23 |
+
# Video de introducción
|
24 |
video = gr.Video(value="video.mp4", label="Video de Introducción")
|
25 |
|
26 |
+
# Título para carruseles de imágenes
|
27 |
gr.Markdown("### Carruseles de Imágenes")
|
28 |
+
|
29 |
+
# Carruseles de imágenes
|
30 |
for category, images_list in image_carousel_data.items():
|
31 |
gr.Markdown(f"#### {category}")
|
32 |
+
gallery_items = [(item["image"], item["description"]) for item in images_list]
|
33 |
+
gr.Gallery(value=gallery_items, label=category, show_label=False)
|
34 |
+
|
35 |
+
# Botón de descarga de informe
|
36 |
+
gr.File(label="Descargar Informe", value="Reporte.pdf")
|
|
|
|
|
|
|
|
|
|
|
37 |
|
38 |
+
# ChatBot y entrada de texto
|
39 |
+
chatbot_output = gr.Chatbot(label="ChatBot", elem_id="chatbot_output")
|
40 |
+
chatbot_input = gr.Textbox(label="Tu mensaje", elem_id="chatbot_input")
|
41 |
+
submit_button = gr.Button("Enviar")
|
42 |
+
chatbot_history = gr.State(value=[])
|
43 |
|
44 |
+
# Opciones de búsqueda
|
45 |
+
selection = gr.Radio(
|
46 |
+
["Solo Búsqueda Vectorial", "Solo Yi-Coder", "Ambos (basado en umbral de similitud)"],
|
47 |
+
label="Seleccione el modo de búsqueda",
|
48 |
+
value="Ambos (basado en umbral de similitud)"
|
49 |
+
)
|
50 |
+
# Sliders para umbral de similitud y longitud máxima
|
51 |
+
similarity_threshold_slider = gr.Slider(
|
52 |
+
minimum=0.0, maximum=1.0, value=SIMILARITY_THRESHOLD_DEFAULT, step=0.01,
|
53 |
+
label="Umbral de similitud (solo para 'Ambos')"
|
54 |
+
)
|
55 |
+
max_length_slider = gr.Slider(
|
56 |
+
minimum=1, maximum=1000, value=MAX_LENGTH_DEFAULT,
|
57 |
+
label="Longitud máxima de tokens (solo para Yi-Coder)"
|
58 |
+
)
|
59 |
+
# Instrucción del sistema
|
60 |
+
system_prompt_input = gr.Textbox(
|
61 |
+
label="Instrucción del sistema", value=SYSTEM_PROMPT, lines=2
|
62 |
+
)
|
63 |
|
64 |
+
# Imagen asociada
|
65 |
+
image_url = gr.State(value=None)
|
66 |
+
image_output = gr.Image(label="Imagen asociada")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
|
68 |
+
# Definir funciones de procesamiento
|
69 |
+
def on_submit(message, history, selected_option, similarity_threshold, system_prompt, max_length):
|
70 |
+
history, new_history, image = process_input(
|
71 |
+
message, history, selected_option, similarity_threshold, system_prompt, max_length
|
72 |
+
)
|
73 |
+
return history, new_history, image
|
74 |
|
75 |
+
# Configurar eventos de clic para el chatbot
|
76 |
+
submit_button.click(
|
77 |
+
on_submit,
|
78 |
+
inputs=[
|
79 |
+
chatbot_input, chatbot_history, selection,
|
80 |
+
similarity_threshold_slider, system_prompt_input, max_length_slider
|
81 |
+
],
|
82 |
+
outputs=[chatbot_output, chatbot_history, image_url]
|
83 |
+
)
|
84 |
|
85 |
+
# Actualizar la imagen cuando se cambie la URL
|
86 |
+
image_url.change(fn=update_image, inputs=image_url, outputs=image_output)
|
|
|
|
|
|
|
|
|
|
|
87 |
|
88 |
return demo
|