Spaces:
Runtime error
Runtime error
File size: 5,239 Bytes
d1701ad |
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 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
from dotenv import load_dotenv
load_dotenv()
from utils import *
import gradio as gr
with gr.Blocks() as app:
with gr.Tab('General info'):
client = gr.Textbox(label='Nombre del cliente', placeholder='Inserte el nombre del cliente')
language = gr.Checkboxgroup(
choices=['español', 'ingles', 'portugués'], value='español', label='Idiomas', interactive=True,
info='Seleccione todos los idiomas que el chatbot va a hablar (al menos debe tener 1 idioma)'
)
name = gr.Dropdown(
choices=['Bella'], value='Bella', label='Nombre del chatbot',
info='Seleccione el nombre del chatbot, si no se encuentra en la lista, contacte al administrador'
)
num_questions = gr.Number(
value=5, minimum=2, maximum=10, label='Número preguntas', interactive=True,
info='Máximo numero de preguntas que puede hacer el usuario.'
)
with gr.Tab('Images'):
base_image = gr.Image(label='Imagen base para los videos', sources=['upload'])
with gr.Tab('Greeting and goodbye'):
_ = gr.Markdown(
'Ingrese los saludos, despedidas y mensajes de error que deba usar el chatbot.'
)
with gr.Row():
greet = gr.Textbox(label='Mensaje', info='Ingrese el mensaje a decir por el chatbot.')
type_greet = gr.Dropdown(
choices=['Saludo', 'Despedida', 'Error'], value='Saludo', interactive=True,
info='Seleccione si es saludo, despedida o mensaje de error.'
)
send_greet_button = gr.Button(value='Añadir')
messages_table = gr.DataFrame(
headers=['Eliminar', 'Tipo mensaje', 'Mensaje'], type='array', interactive=False
)
with gr.Tab('Random data'):
_ = gr.Markdown(
'Si quiere que Bella diga algunos datos random mientras busca la información, ingrese dichos párrafos aca.'
)
with gr.Row():
random_data = gr.Text(placeholder='Ingrese el dato random', label='Dato random')
send_random_button = gr.Button(value='Añadir')
random_table = gr.DataFrame(headers=['Eliminar', 'Dato random'], type='array', interactive=False)
with gr.Tab('Questions - Context'):
with gr.Row():
question = gr.Text(placeholder='Ingrese su pregunta', label='Pregunta')
context = gr.Text(placeholder='Ingrese el párrafo u oración que contesta dicha pregunta', label='Contexto')
send_question_button = gr.Button(value='Añadir')
questions_table = gr.DataFrame(
headers=['Eliminar', 'Pregunta', 'Contexto'], type='array', interactive=False
)
with gr.Tab('General prompt'):
general_prompt = gr.Text(placeholder='Ingrese el prompt general del bot', label='Prompt')
with gr.Tab('Context prompt'):
context_prompt = gr.Text(placeholder='Ingrese el prompt usado para encontrar el contexto', label='Prompt')
with gr.Tab('Create chatbot'):
_ = gr.Markdown(
"Asegúrese que toda la información este correcta antes de enviarla."
)
create_chatbot_button = gr.Button(value='Crear chatbot')
with gr.Tab('Test'):
with gr.Row():
with gr.Column():
with gr.Row():
video = gr.Video(interactive=False, label='Video', autoplay=True)
with gr.Row():
output_audio = gr.Audio(interactive=False, label='Audio', autoplay=True)
with gr.Column():
with gr.Row():
chat = gr.Chatbot(label='Chat')
with gr.Row():
text = gr.Text(label='Write your question')
with gr.Tab('Submit'):
_ = gr.Markdown(
"Asegúrese que hizo las suficientes pruebas para aprobar el chatbot."
)
submit_button = gr.Button(value='ENVIAR!')
output_file = gr.File(interactive=False, label='Output file')
# ----------------------------------------------- ACTIONS -----------------------------------------------------
# Add info to the tables
send_greet_button.click(
add_data_table, [messages_table, type_greet, greet], [messages_table, greet]
)
send_random_button.click(
add_data_table, [random_table, random_data], [random_table, random_data]
)
send_question_button.click(
add_data_table, [questions_table, question, context], [questions_table, question, context]
)
# Remove info from the tables
messages_table.select(
remove_data_table, messages_table, messages_table
)
random_table.select(
remove_data_table, random_table, random_table
)
questions_table.select(
remove_data_table, questions_table, questions_table
)
# Create the chatbot: create media and vectorstore
create_chatbot_button.click(
lambda: gr.Button(value='Creating chatbot...', interactive=False),
None,
create_chatbot_button
).then(
create_chatbot,
[client, language, name, base_image, messages_table, random_table, questions_table],
create_chatbot_button
)
app.launch(debug=True)
|