File size: 4,176 Bytes
e8aad19
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import pandas as pd
from tool_info import TOOL_INFO
from modules.module_connection import BiasWordExplorerConnector


# --- Interface ---
def interface(
    embedding, # Class Embedding instance
    available_logs: bool,
    lang: str="es"
) -> gr.Blocks:

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


    # --- Init vars ---
    connector = BiasWordExplorerConnector(
        embedding=embedding,
        lang=lang,
        logs_file_name = f"logs_edia_we_wordbias_{lang}" if available_logs else None
    )

    # --- Load language ---
    labels = pd.read_json(
        f"language/{lang}.json"
    )["BiasWordExplorer_interface"]

    # --- Interface ---
    interface = gr.Blocks()

    with interface:
        gr.Markdown(
            value=labels["step1"]
        )
        with gr.Row():
            with gr.Column():
                with gr.Row():
                    diagnose_list = gr.Textbox(
                        lines=2,
                        label=labels["wordListToDiagnose"]
                    )
                with gr.Row():
                    gr.Markdown(
                        value=labels["step2&2Spaces"]
                    )
                with gr.Row():
                    wordlist_1 = gr.Textbox(
                        lines=2,
                        label=labels["wordList1"]
                    )
                    wordlist_2 = gr.Textbox(
                        lines=2, 
                        label=labels["wordList2"]
                    )
                with gr.Row():
                    gr.Markdown(
                        value=labels["step2&4Spaces"]
                    )
                with gr.Row():
                    wordlist_3 = gr.Textbox(
                        lines=2, 
                        label=labels["wordList3"]
                    )
                    wordlist_4 = gr.Textbox(
                        lines=2, 
                        label=labels["wordList4"]
                    )

            with gr.Column():
                with gr.Row():
                    bias2d = gr.Button(
                        value=labels["plot2SpacesButton"]
                    )
                with gr.Row():
                    bias4d = gr.Button(
                        value=labels["plot4SpacesButton"]
                    )
                with gr.Row():
                    err_msg = gr.Markdown(
                        label="", 
                        visible=True
                    )
                with gr.Row():
                    bias_plot = gr.Plot(
                        label="", 
                        show_label=False
                    )

        with gr.Row():
            examples = gr.Examples(
                fn=connector.calculate_bias_2d,
                inputs=[wordlist_1, wordlist_2, diagnose_list],
                outputs=[bias_plot, err_msg],
                examples=examples1_explorar_sesgo_en_palabras,
                label=labels["examples2Spaces"]
            )
        with gr.Row():
            examples = gr.Examples(
                fn=connector.calculate_bias_4d,
                inputs=[wordlist_1, wordlist_2,wordlist_3, wordlist_4, diagnose_list],
                outputs=[
                    bias_plot, err_msg
                ],
                examples=examples2_explorar_sesgo_en_palabras,
                label=labels["examples4Spaces"]
            )

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

        bias2d.click(
            fn=connector.calculate_bias_2d,
            inputs=[wordlist_1, wordlist_2, diagnose_list],
            outputs=[bias_plot, err_msg]
        )

        bias4d.click(
            fn=connector.calculate_bias_4d,
            inputs=[wordlist_1, wordlist_2,
                    wordlist_3, wordlist_4, diagnose_list],
            outputs=[bias_plot, err_msg]
        )

    return interface