|
import gradio |
|
|
|
from functions import * |
|
|
|
|
|
with gr.Blocks() as app: |
|
msg_history = gr.State() |
|
waiting_time = gr.State([]) |
|
is_working = gr.State(True) |
|
|
|
|
|
with gr.Row() as welcoming: |
|
with gr.Column(): |
|
done = gr.State('') |
|
|
|
with gr.Row(): |
|
gr.Markdown( |
|
""" |
|
# Holiii |
|
Bienvenido al chat. Soy Roomie. Me gustaria saber un poco mas de ti antes de continuar. |
|
""" |
|
) |
|
|
|
with gr.Row(): |
|
with gr.Column(): |
|
name = gr.Textbox(lines=1, max_lines=1, label='¿Cual es tu nombre?') |
|
age = gr.Number(label='¿Cual es tu edad?') |
|
country = gr.Dropdown(label='¿Desde que pais me visitas?', choices=get_countries()) |
|
send = gr.Button(label='Continuar') |
|
|
|
with gr.Column(): |
|
image = gr.Image(value="assets/images/bienvenida.jpg") |
|
|
|
|
|
with gr.Column(visible=False) as chat_box: |
|
gr.Markdown("""Perfecto! Un gusto tenerte aca""") |
|
chatbot = gr.Chatbot() |
|
message = gr.Textbox(label='Envia tu mensaje') |
|
|
|
|
|
with gr.Column(visible=False) as error_window: |
|
gr.Markdown( |
|
"""Oh no, Roomie se tuvo que ir a su planeta. |
|
Lo sentimos mucho. Conectate mas tarde para hablar con el""" |
|
) |
|
gr.Image(value="assets/images/despedida.jpg") |
|
|
|
|
|
|
|
|
|
send.click( |
|
check_info, |
|
[name, age, country], |
|
[send, image, welcoming, chat_box, msg_history] |
|
) |
|
|
|
|
|
message.submit( |
|
get_answer, |
|
[message, msg_history, chatbot, waiting_time], |
|
[message, msg_history, chatbot, waiting_time, is_working], |
|
).then( |
|
check_closing, |
|
[is_working], |
|
[chat_box, error_window] |
|
) |
|
|
|
app.queue(concurrency_count=100) |
|
app.launch(debug=True) |
|
|