Spaces:
Sleeping
Sleeping
File size: 4,473 Bytes
5e4f52c 613b36f 5e4f52c 613b36f 11daf1f 613b36f df5eeb2 f68474a 613b36f 5e4f52c 613b36f 11daf1f 613b36f 5e4f52c 613b36f cec9b07 5e4f52c 613b36f 5e4f52c 613b36f 5e4f52c 613b36f 5e4f52c 613b36f 5e4f52c 613b36f 5e4f52c 613b36f 5e4f52c cec9b07 613b36f 5e4f52c 613b36f 5e4f52c cec9b07 5e4f52c cec9b07 5e4f52c cec9b07 613b36f cec9b07 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# ui.py
import gradio as gr
from config import SIMILARITY_THRESHOLD_DEFAULT, SYSTEM_PROMPT, MAX_LENGTH_DEFAULT
import os
# Define the theme (you can keep your custom theme)
def get_theme():
theme = gr.themes.Default(
primary_hue="indigo",
# ... (rest of your theme configuration)
)
return theme
# Load images and descriptions
def load_images():
image_carousel_data = {
"NASA": [
{"image": "images/rld1.png", "description": "NASA"},
{"image": "images/rld2.png", "description": "NASA"},
],
# Add more categories and images as needed
}
return image_carousel_data
# Build the interface
def build_interface(process_input, send_preset_question, update_image):
theme = get_theme()
image_carousel_data = load_images()
with gr.Blocks(theme='upsatwal/mlsc_tiet') as demo:
with gr.Row():
with gr.Column(scale=0.8):
# Add the video
video = gr.Video(value="video.mp4", label="Video de Introducción")
# Image Galleries
gr.Markdown("### Carruseles de Imágenes")
for category, images_list in image_carousel_data.items():
gr.Markdown(f"#### {category}")
# Use gr.Gallery instead of gr.Carousel
gallery_items = []
for item in images_list:
gallery_items.append((item["image"], item["description"]))
gr.Gallery(
value=gallery_items,
label=category,
show_label=False,
elem_id=None
)
# Download button
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=[])
# Add selection options
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")
# Define processing functions
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
# Configure click events for the 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
|