Spaces:
Sleeping
Sleeping
| from functions import * | |
| scores_parameters, authors, p_conversation = get_main_data() | |
| with gr.Blocks() as app: | |
| msg_history = gr.State() # Messages with the format used by OpenAI | |
| waiting_time = gr.State([]) # Seconds needed to get each answer | |
| prompt_conversation = gr.State(p_conversation) | |
| summary = gr.State('') | |
| num_interactions = gr.State(0) | |
| cost = gr.State([]) | |
| with gr.Tab('Test Chats'): | |
| with gr.Row(): | |
| author = gr.Dropdown(authors, value=authors[0], label='Author', interactive=True) | |
| chat_btn = gr.Button(value='Start chat') | |
| # ------------------------------------- Chat ------------------------------------------- | |
| chatbot = gr.Chatbot(label='Chat', visible=False) | |
| message = gr.Textbox(label='Message', visible=False) | |
| # ------------------------------------- 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=['Aprovado', 'No aprovado', 'No aplica'], 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( | |
| innit_bot, [prompt_conversation], [msg_history] | |
| ).then( | |
| make_noninteractive, None, [author] | |
| ).then( | |
| make_visible, None, [chatbot, message, scores_row] | |
| ) | |
| message.submit( | |
| get_answer, | |
| [message, msg_history, chatbot, waiting_time, num_interactions, summary, cost], | |
| [message, msg_history, chatbot, waiting_time, num_interactions, summary, cost] | |
| ) | |
| scores_btn.click( | |
| save_scores, | |
| [author, chatbot, waiting_time, opinion_box, cost] + scores, | |
| scores_box | |
| ) | |
| app.launch(debug=True, auth=(os.environ.get('USERNAME'), os.environ.get('PASSWORD'))) | |