AudioLLMs/AudioBench-Leaderboard-Extend
25
1import streamlit as st2import datasets3import numpy as np4 5import html6 7 8def show_examples(category_name, dataset_name, model_lists, display_model_names):9 st.divider()10 sample_folder = f"./examples/{category_name}/{dataset_name}"11 12 dataset = datasets.load_from_disk(sample_folder)13 14 for index in range(len(dataset)):15 with st.container():16 st.markdown(f'##### Example-{index+1}')17 col1, col2 = st.columns([0.3, 0.7], vertical_alignment="center")18 19 # with col1:20 st.audio(f'{sample_folder}/sample_{index}.wav', format="audio/wav")21 22 if dataset_name in ['CN-College-Listen-MCQ-Test', 'DREAM-TTS-MCQ-Test']:23 24 choices = dataset[index]['other_attributes']['choices'] 25 if isinstance(choices, str):26 choices_text = choices27 elif isinstance(choices, list):28 choices_text = ' '.join(i for i in choices)29 30 question_text = f"""{dataset[index]['instruction']['text']} {choices_text}"""31 else:32 question_text = f"""{dataset[index]['instruction']['text']}"""33 34 question_text = html.escape(question_text)35 36 # st.divider()37 with st.container():38 custom_css = """39 <style>40 .my-container-table, p.my-container-text {41 background-color: #fcf8dc;42 padding: 10px;43 border-radius: 5px;44 font-size: 13px;45 # height: 50px;46 word-wrap: break-word47 }48 </style>49 """50 st.markdown(custom_css, unsafe_allow_html=True)51 52 model_lists.sort()53 54 s = f"""<tr>55 <td><b>REFERENCE</td>56 <td><b>{html.escape(question_text.replace('(A)', '<br>(A)').replace('(B)', '<br>(B)').replace('(C)', '<br>(C)'))}57 </td>58 <td><b>{html.escape(dataset[index]['answer']['text'])}59 </td>60 </tr>61 """62 if dataset_name in ['CN-College-Listen-MCQ-Test', 'DREAM-TTS-MCQ-Test']:63 for model in model_lists:64 try:65 66 model_prediction = dataset[index][model]['model_prediction']67 model_prediction = model_prediction.replace('<','').replace('>','').replace('\n','(newline)').replace('*','')68 69 s += f"""<tr>70 <td>{display_model_names[model]}</td>71 <td>72 {dataset[index][model]['text'].replace('Choices:', '<br>Choices:').replace('(A)', '<br>(A)').replace('(B)', '<br>(B)').replace('(C)', '<br>(C)') 73 }74 </td>75 <td>{html.escape(model_prediction)}</td>76 </tr>"""77 except:78 print(f"{model} is not in {dataset_name}")79 continue80 else:81 for model in model_lists:82 83 print(dataset[index][model]['model_prediction'])84 85 try:86 87 model_prediction = dataset[index][model]['model_prediction']88 model_prediction = model_prediction.replace('<','').replace('>','').replace('\n','(newline)').replace('*','')89 90 s += f"""<tr>91 <td>{display_model_names[model]}</td>92 <td>{html.escape(dataset[index][model]['text'])}</td>93 <td>{html.escape(model_prediction)}</td>94 </tr>"""95 except:96 print(f"{model} is not in {dataset_name}")97 continue98 99 100 body_details = f"""<table style="table-layout: fixed; width:100%">101 <thead>102 <tr style="text-align: center;">103 <th style="width:20%">MODEL</th>104 <th style="width:30%">QUESTION</th>105 <th style="width:50%">MODEL PREDICTION</th>106 </tr>107 {s}108 </thead>109 </table>"""110 111 st.markdown(f"""<div class="my-container-table">112 {body_details}113 </div>""", unsafe_allow_html=True)114 115 st.text("")116 117 st.divider()118 119 120 