File size: 6,636 Bytes
f5625dd
 
 
 
7774c4b
f5625dd
 
7774c4b
f5625dd
 
 
7774c4b
1c7afe3
 
7774c4b
 
 
 
 
 
 
 
 
f5625dd
 
 
 
 
 
 
 
 
 
 
 
937bc55
f5625dd
 
 
308cc2e
 
79b0b1e
 
 
 
 
 
 
308cc2e
 
7774c4b
 
 
 
 
 
79b0b1e
 
7774c4b
308cc2e
 
f5625dd
 
 
 
 
c492340
c5b51ce
f5625dd
 
 
 
 
 
 
 
 
 
 
 
 
 
308cc2e
f5625dd
7774c4b
f5625dd
 
 
 
 
308cc2e
f5625dd
 
 
 
1b4905d
f5625dd
 
 
 
 
 
 
 
 
 
7774c4b
 
 
f5625dd
 
 
 
 
 
 
 
7774c4b
 
 
 
7632295
7774c4b
 
 
 
 
 
 
 
79b0b1e
7774c4b
 
 
 
 
 
 
7632295
 
 
7774c4b
 
 
 
 
 
 
 
7632295
 
 
7774c4b
7632295
79b0b1e
7774c4b
 
 
 
 
 
 
 
 
79b0b1e
7632295
 
7774c4b
 
 
 
 
 
 
 
 
 
 
 
 
 
f5625dd
 
 
c5b51ce
308cc2e
 
 
f5625dd
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
import streamlit as st
import pandas as pd
import numpy as np
from streamlit_echarts import st_echarts
from streamlit.components.v1 import html
# from PIL import Image 
from app.show_examples import *
import pandas as pd

# huggingface_image = Image.open('style/huggingface.jpg')

# other info 
#path = "./AudioBench-Leaderboard/additional_info/Leaderboard-Rename.xlsx"
path = "./additional_info/Leaderboard-Rename.xlsx"
info_df = pd.read_excel(path)

# def nav_to(value):
#     try:
#         url = links_dic[str(value).lower()]
#         js = f'window.open("{url}", "_blank").then(r => window.parent.location.href);'
#         st_javascript(js)
#     except:
#         pass

def draw(folder_name, category_name, dataset_name, metrics):
    
    folder = f"./results/{metrics}/"

    display_names = {
        'SU': 'Speech Understanding',
        'ASU': 'Audio Scene Understanding',
        'VU': 'Voice Understanding'
    }
    
    data_path = f'{folder}/{category_name.lower()}.csv'
    chart_data = pd.read_csv(data_path).round(3)
    new_dataset_name = dataset_name.replace('-', '_').lower()
    chart_data = chart_data[['Model', new_dataset_name]]
    
    st.markdown("""
                <style>
                .stMultiSelect [data-baseweb=select] span {
                    max-width: 800px;
                    font-size: 0.9rem;
                    background-color: #3C6478 !important; /* Background color for selected items */
                    color: white; /* Change text color */
                    back
                }
                </style>
                """, unsafe_allow_html=True)
    
    # remap model names
    display_model_names = {key.strip() :val.strip() for key, val in zip(info_df['AudioBench'], info_df['Proper Display Name'])}
    chart_data['Model'] = chart_data['Model'].map(display_model_names)

    models = st.multiselect("Please choose the model", 
                            sorted(chart_data['Model'].tolist()), 
                            default =  sorted(chart_data['Model'].tolist()))
    
    chart_data = chart_data[chart_data['Model'].isin(models)]
    
    chart_data = chart_data.sort_values(by=[new_dataset_name], ascending=True).dropna(axis=0)

    if len(chart_data) == 0:
        return
    
    min_value = round(chart_data.iloc[:, 1::].min().min() - 0.1*chart_data.iloc[:, 1::].min().min(), 1) 
    max_value = round(chart_data.iloc[:, 1::].max().max() + 0.1*chart_data.iloc[:, 1::].max().max(), 1)         

    options = {
        "title": {"text": f"{display_names[folder_name.upper()]}"},
        "tooltip": {
            "trigger": "axis",
            "axisPointer": {"type": "cross", "label": {"backgroundColor": "#6a7985"}},
            "triggerOn": 'mousemove',
        },
        "legend": {"data": ['Overall Accuracy']},
        "toolbox": {"feature": {"saveAsImage": {}}},
        "grid": {"left": "3%", "right": "4%", "bottom": "3%", "containLabel": True},
        "xAxis": [
            {
                "type": "category",
                "boundaryGap": True,
                "triggerEvent": True,
                "data":  chart_data['Model'].tolist(),
            }
        ],
        "yAxis": [{"type": "value", 
                    "min": min_value,
                    "max": max_value, 
                    "boundaryGap": True
                    # "splitNumber": 10
                    }],
        "series": [{
                "name": f"{dataset_name}",
                "type": "bar",
                "data": chart_data[f'{new_dataset_name}'].tolist(),
            }],
    }
    
    events = {
        "click": "function(params) { return params.value }"
    }

    value = st_echarts(options=options, events=events, height="500px")
    
    # if value != None:
    #     # print(value)
    #     nav_to(value)

    # if value != None:
    #     highlight_table_line(value)

    '''
    Show table
    '''
    # st.divider()
    with st.container():
        # st.write("")
        st.markdown('##### TABLE')
        custom_css = """
                   
                    """
        st.markdown(custom_css, unsafe_allow_html=True)
        
        model_link = {key.strip(): val for key, val in zip(info_df['Proper Display Name'], info_df['Link'])}

        s = ''
        for model in models:
            try:
                # <td align="center"><input type="checkbox" name="select"></td>
                s += f"""<tr>
                    <td><a href={model_link[model]}>{model}</a></td>
                    <td>{chart_data[chart_data['Model'] == model][new_dataset_name].tolist()[0]}</td>
                </tr>"""
            except:
                # print(f"{model} is not in {dataset_name}")
                continue
        
        # select all function
        select_all_function = """<script>
            function toggle(source) {
                var checkboxes = document.querySelectorAll('input[type="checkbox"]');
                for (var i = 0; i < checkboxes.length; i++) {
                    if (checkboxes[i] != source)
                        checkboxes[i].checked = source.checked;
                }
            }
        </script>"""
        st.markdown(f"""
                    <div class="select_all">{select_all_function}</div>
                    """, unsafe_allow_html=True)

        info_body_details = f"""
            <table style="width:80%">
                <thead>
                    <tr style="text-align: center;">
                        <th style="width:45%">MODEL</th>
                        <th style="width:45%">{dataset_name}</th>
                    </tr>
                    {s}
                </thead>
            </table>
        """
        #<th style="width:10%"><input type="checkbox" onclick="toggle(this);"></th>
        # html_code = custom_css + select_all_function + info_body_details
        # html(html_code, height = 300)
                    
        st.markdown(f"""
                    <div class="my-data-table">{info_body_details}</div>
                    """, unsafe_allow_html=True)
        
        
    # st.dataframe(chart_data,
    #             #  column_config = {
    #             #      "Link": st.column_config.LinkColumn(
    #             #          display_text= st.image(huggingface_image)
    #             #      ),
    #             #  }, 
    #                 hide_index = True, 
    #                 use_container_width=True)
    '''
    show samples
    '''
    if dataset_name in ['Earnings21-Test', 'Earnings22-Test', 'Tedlium3-Long-form-Test']:
        pass
    else:
        show_examples(category_name, dataset_name, chart_data['Model'].tolist())