Spaces:
Sleeping
Sleeping
import time | |
from functions import * | |
scores_parameters, authors = get_main_data() | |
with (gr.Blocks() as app): | |
user_id = gr.State('') # id used to find the chat into the database | |
with gr.Tab('Test Chats'): | |
with gr.Row() as select_author: | |
author = gr.Dropdown(authors, value=authors[0], label='Author', interactive=True) | |
language = gr.Dropdown( | |
value='Español', choices=['Español', 'English', 'Português'], label='Language' | |
) | |
chat_btn = gr.Button(value='Start chat') | |
# ------------------------------------- Chat ------------------------------------------- | |
with gr.Row(visible=False) as chatbot: | |
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.Row(): | |
checkbox = gr.Checkbox( | |
label='Get video', info='Remember that this has a cost' | |
) | |
radio = gr.Radio( | |
choices=['small', 'big'], value='small', | |
label='GPU', info='Select the size of GPU (at the moment they are the same)', | |
visible=False | |
) | |
predict_language = gr.Checkbox(label='Predict language', visible=False) | |
with gr.Column(): | |
with gr.Row(): | |
chat = gr.Chatbot(label='Chat') | |
with gr.Row(): | |
text = gr.Text(label='Write your question') | |
audio = gr.Audio(sources=['microphone'], type='filepath', label='Tell me your question') | |
with gr.Row(): | |
button_text = gr.Button(value='Submit text') | |
button_audio = gr.Button(value='Submit audio') | |
# ------------------------------------- Result's tab --------------------------------------- | |
with gr.Tab('Save results'): | |
with gr.Row(visible=False) as scores_row: | |
with gr.Column(scale=75): | |
with gr.Row(): | |
scores = [ | |
gr.Radio(choices=['Aprobado', 'No aprobado'], label=parameter) | |
for parameter in scores_parameters | |
] | |
with gr.Column(scale=25): | |
opinion_box = gr.Textbox(label='Opinion') | |
scores_btn = gr.Button(value='Send scores') | |
scores_box = gr.Textbox(label='Status', interactive=False) | |
# -------------------------------------- Actions ----------------------------------------- | |
chat_btn.click( | |
make_invisible, None, select_author | |
).then( | |
make_visible, None, [chatbot, scores_row] | |
).then( | |
init_chatbot, [chat, language], [video, chat, user_id] | |
) | |
button_text.click( | |
play_searching, language, video | |
).then( | |
lambda: time.sleep(6), None, None | |
).then( | |
get_answer_text, | |
[text, chat, user_id, checkbox, radio, predict_language], | |
[video, output_audio, chat, text] | |
) | |
button_audio.click( | |
play_searching, language, video | |
).then( | |
lambda: time.sleep(6), None, None | |
).then( | |
get_answer_audio, | |
[audio, chat, user_id, checkbox, radio, predict_language], | |
[video, output_audio, chat, audio] | |
) | |
scores_btn.click( | |
save_scores, | |
[author, chat, opinion_box] + scores, | |
scores_box | |
) | |
video.end( | |
lambda: 'videos/waiting.mp4', None, video | |
) | |
output_audio.stop( | |
lambda: None, None, output_audio | |
) | |
app.queue() | |
app.launch(debug=True, auth=(os.environ.get('USERNAME'), os.environ.get('PASSWORD'))) | |