File size: 3,955 Bytes
ddec2c4
 
 
 
 
f1ad590
ddec2c4
 
 
 
 
f1ad590
ddec2c4
 
f1ad590
 
 
 
 
 
ddec2c4
 
c4d5284
 
ddec2c4
 
 
 
f1ad590
ddec2c4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f1ad590
ddec2c4
 
 
 
 
 
 
 
 
 
 
 
 
 
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
130
131
132
133
134
135
136
137
138
import gradio as gr
import pandas as pd
from tool_info import TOOL_INFO
from modules.module_logsManager import HuggingFaceDatasetSaver
from modules.module_connection import CrowsPairsExplorerConnector



def interface(
    language_model: str, 
    available_logs: bool, 
    lang: str="es"
) -> gr.Blocks:

    # -- Load examples --
    if lang == 'es':
        from examples.examples_es import examples_crows_pairs
    elif lang == 'en':
        from examples.examples_en import examples_crows_pairs

    # --- Init logs ---
    log_callback = HuggingFaceDatasetSaver(
        available_logs=available_logs,
        dataset_name=f"logs_edia_lmodels_{lang}"
    )

    # --- Init vars ---
    connector = CrowsPairsExplorerConnector(
        language_model=language_model
    )
    
    # --- Load language ---
    labels = pd.read_json(
        f"language/{lang}.json"
    )["CrowsPairs_interface"]

    # --- Interface ---
    iface = gr.Blocks(
        css=".container {max-width: 90%; margin: auto;}"
    )

    with iface:
        with gr.Row():
            gr.Markdown(
                value=labels["title"]
            )
        
        with gr.Row():
            with gr.Column():
                with gr.Group():
                    sent0 = gr.Textbox(
                        label=labels["sent0"],
                        placeholder=labels["commonPlacholder"]
                    )
                    sent2 = gr.Textbox(
                        label=labels["sent2"],
                        placeholder=labels["commonPlacholder"]
                    )
                    sent4 = gr.Textbox(
                        label=labels["sent4"],
                        placeholder=labels["commonPlacholder"]
                    )

            with gr.Column():
                with gr.Group():
                    sent1 = gr.Textbox(
                        label=labels["sent1"],
                        placeholder=labels["commonPlacholder"]
                    )
                    sent3 = gr.Textbox(
                        label=labels["sent3"],
                        placeholder=labels["commonPlacholder"]
                    )
                    sent5 = gr.Textbox(
                        label=labels["sent5"],
                        placeholder=labels["commonPlacholder"]
                    )

        with gr.Row():  
            btn = gr.Button(
                value=labels["compareButton"]
            )
        with gr.Row():  
            out_msj = gr.Markdown(
                value=""
            )
        
        with gr.Row():
            with gr.Group():
                gr.Markdown(
                    value=labels["plot"]
                )
                dummy = gr.CheckboxGroup(
                    value="", 
                    show_label=False, 
                    choices=[]
                )
                out = gr.HTML(
                    label=""
                )

        with gr.Row():
            examples = gr.Examples(
                inputs=[sent0, sent1, sent2, sent3, sent4, sent5],
                examples=examples_crows_pairs,
                label=labels["examples"]
            )

        with gr.Row(): 
            gr.Markdown(
                value=TOOL_INFO
            )

        btn.click(  
            fn=connector.compare_sentences,
            inputs=[sent0, sent1, sent2, sent3, sent4, sent5],
            outputs=[out_msj, out, dummy]
        )

        # --- Logs ---
        save_field = [sent0, sent1, sent2, sent3, sent4, sent5]
        log_callback.setup(
            components=save_field, 
            flagging_dir=f"logs_crows_pairs"
        )
        
        btn.click(
            fn=lambda *args: log_callback.flag(
                flag_data=args,
                flag_option="crows_pairs",
                username="vialibre"
            ),
            inputs=save_field,
            outputs=None, 
            preprocess=False
        )
    
    return iface