Team Ai
Apppublic

AudioLLMs/AudioBench-Leaderboard-Extend

sourceHugging Faceapache-2.0updated 2y agoView on Hugging Face
25likes
summarization.py138 linesDownload Raw Back to app
1import streamlit as st2import pandas as pd3import numpy as np4 5import json6 7from streamlit_echarts import st_echarts8from streamlit.components.v1 import html9# from PIL import Image 10from app.show_examples import *11from app.content import *12 13import pandas as pd14from typing import List15 16from model_information import get_dataframe17 18info_df = get_dataframe()19 20def sum_table_mulit_metrix(dataset_displayname_list, metric):21 22    with open('organize_model_results.json', 'r') as f:23        organize_model_results = json.load(f)24 25    dataset_results = {}26 27    for dataset_displayname in dataset_displayname_list:28        dataset_nickname = displayname2datasetname[dataset_displayname]29        model_results = organize_model_results[dataset_nickname][metric]30        model_name_mapping = {key.strip(): val for key, val in zip(info_df['Original Name'], info_df['Proper Display Name'])}31        model_results      = {model_name_mapping.get(key, key): val for key, val in model_results.items()}32 33        dataset_results[dataset_displayname] = model_results34 35    df_results = pd.DataFrame(dataset_results)36 37    # Reset index to have models as a column38    df_results.reset_index(inplace=True)39    df_results.rename(columns={"index": "Model"}, inplace=True)40    chart_data = df_results    41 42    selected_columns = [i for i in chart_data.columns if i != 'Model']43    chart_data['Average'] = chart_data[selected_columns].mean(axis=1)44 45    # Update dataset name in table46    chart_data = chart_data.rename(columns=datasetname2diaplayname)47    48    st.markdown("""49                <style>50                .stMultiSelect [data-baseweb=select] span {51                    max-width: 800px;52                    font-size: 0.9rem;53                    background-color: #3C6478 !important; /* Background color for selected items */54                    color: white; /* Change text color */55                    back56                }57                </style>58                """, unsafe_allow_html=True)59    60    # remap model names61    display_model_names = {key.strip() :val.strip() for key, val in zip(info_df['Original Name'], info_df['Proper Display Name'])}62    chart_data['model_show'] = chart_data['Model'].map(lambda x: display_model_names.get(x, x))63 64    models = st.multiselect("Please choose the model", 65                            sorted(chart_data['model_show'].tolist()), 66                            default = sorted(chart_data['model_show'].tolist()),67                            )68    69    chart_data = chart_data[chart_data['model_show'].isin(models)].dropna(axis=0)70 71    if len(chart_data) == 0: return72 73    # = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =74    '''75    Show Table76    '''77    with st.container():78        st.markdown(f'##### TABLE')79 80        model_link = {key.strip(): val for key, val in zip(info_df['Proper Display Name'], info_df['Link'])}81 82        chart_data['model_link'] = chart_data['model_show'].map(model_link) 83 84        tabel_columns = [i for i in chart_data.columns if i not in ['Model', 'model_show']]85        column_to_front = 'Average'86        new_order = [column_to_front] + [col for col in tabel_columns if col != column_to_front]87        88        chart_data_table = chart_data[['model_show'] + new_order]89        90 91        # Format numeric columns to 2 decimal places92        chart_data_table[chart_data_table.columns[1]] = chart_data_table[chart_data_table.columns[1]].apply(lambda x: round(float(x), 3) if isinstance(float(x), (int, float)) else float(x))93 94        if metric == 'wer':95            ascend = True96        else:97            ascend= False98 99        chart_data_table = chart_data_table.sort_values(100                by=['Average'],101                ascending=ascend102            ).reset_index(drop=True)103        104        # Highlight the best performing model105        def highlight_first_element(x):106            # Create a DataFrame with the same shape as the input107            df_style = pd.DataFrame('', index=x.index, columns=x.columns)108            # Apply background color to the first element in row 0 (df[0][0])109            # df_style.iloc[0, 1] = 'background-color: #b0c1d7; color: white'110            df_style.iloc[0, 1] = 'background-color: #b0c1d7'111 112            return df_style113        114 115        styled_df = chart_data_table.style.format(116            {117                chart_data_table.columns[i]: "{:.3f}" for i in range(1, len(chart_data_table.columns) - 1)118             }119        ).apply(120            highlight_first_element, axis=None121        )122 123        st.dataframe(124                styled_df,125                column_config={126                    'model_show': 'Model',127                    chart_data_table.columns[1]: {'alignment': 'left'},128                    "model_link": st.column_config.LinkColumn(129                        "Model Link",130                    ),131                },132                hide_index=True,133                use_container_width=True134            )135            136    # Only report the last metrics137    st.markdown(f'###### Metric: {metrics_info[metric]}')138