File size: 3,866 Bytes
3041c48
6e2fd22
 
 
 
 
 
 
 
 
 
 
1c0b271
 
 
6e2fd22
 
 
 
 
 
1c0b271
6e2fd22
 
 
aa938da
 
 
 
1c0b271
 
 
aa938da
3041c48
6e2fd22
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1c0b271
6e2fd22
3041c48
6e2fd22
1c0b271
 
3041c48
1c0b271
6e2fd22
1c0b271
6e2fd22
 
 
 
1c0b271
3041c48
 
1c0b271
6e2fd22
1c0b271
6e2fd22
 
 
 
 
 
 
 
 
 
1c0b271
6e2fd22
 
 
 
 
 
 
 
 
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
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')))