File size: 8,151 Bytes
f5625dd 5e2340a f5625dd 62da12f f7a3f90 5e2340a f7a3f90 5e2340a f7a3f90 16943d7 f7a3f90 5e2340a f7a3f90 62da12f 8764f41 f5625dd 308cc2e f5625dd a30610b 8764f41 f5625dd 4237375 a30610b 4237375 62da12f f5625dd a30610b f5625dd 8764f41 f5625dd 8764f41 f5625dd 4237375 f5625dd 4237375 8764f41 62da12f 8764f41 62da12f 8764f41 f5625dd 62da12f f5625dd 8764f41 62da12f f5625dd 62da12f f5625dd 62da12f f5625dd 8764f41 62da12f f5625dd 8764f41 f5625dd 4237375 f5625dd 62da12f f5625dd a30610b 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 191 192 193 194 195 196 197 198 199 |
import streamlit as st
import datasets
import numpy as np
import io
import soundfile as sf
import html
from app.content import displayname2datasetname
def show_dataset_examples(display_name):
st.divider()
dataset_name = displayname2datasetname[display_name]
sample_folder = f"./examples/{dataset_name}"
# load dataset
dataset = datasets.load_from_disk(sample_folder)
for index in range(len(dataset)):
with st.container():
st.markdown(f'##### Example-{index+1}')
col1, col2 = st.columns([0.3, 0.7], vertical_alignment="center")
with col1:
# Convert the NumPy array to a WAV file in memory
bytes_io = io.BytesIO()
sf.write(bytes_io, dataset[index]['context']['audio']['array'], dataset[index]['context']['audio']['sampling_rate'], format='WAV')
bytes_io.seek(0)
# Play audio in Streamlit
st.audio(bytes_io, format='audio/wav')
# st.audio(f'{sample_folder}/sample_{index}.wav', format="audio/wav")
if dataset_name in ['CN-College-Listen-MCQ-Test', 'DREAM-TTS-MCQ-Test']:
choices = dataset[index]['other_attributes']['choices']
if isinstance(choices, str):
choices_text = choices
elif isinstance(choices, list):
choices_text = ' '.join(i for i in choices)
question_text = f"""{dataset[index]['instruction']['text']} {choices_text}"""
else:
question_text = f"""{dataset[index]['instruction']['text']}"""
question_text = html.escape(question_text)
# with st.container():
with col2:
custom_css = """
<style>
.my-container-table, p.my-container-text {
background-color: #fcf8dc;
padding: 10px;
border-radius: 5px;
font-size: 13px;
# height: 50px;
word-wrap: break-word
}
</style>
"""
st.markdown(custom_css, unsafe_allow_html=True)
body_details = f"""<table style="table-layout: fixed; width:100%">
<thead>
<tr style="text-align: center;">
<th style="width:50%">PROMPT</th>
<th style="width:50%">ANSWER</th>
</tr>
<tr>
<td><b>{html.escape(question_text.replace('(A)', '<br>(A)').replace('(B)', '<br>(B)').replace('(C)', '<br>(C)'))}
</td>
<td><b>{html.escape(dataset[index]['answer']['text'])}
</td>
</tr>
</thead>
</table>"""
st.markdown(f"""<div class="my-container-table">
{body_details}
</div>""", unsafe_allow_html=True)
st.text("")
st.divider()
def show_examples(category_name, dataset_name, model_lists, display_model_names):
st.divider()
sample_folder = f"./examples/{category_name}/{dataset_name}"
dataset = datasets.load_from_disk(sample_folder)
for index in range(len(dataset)):
with st.container():
st.markdown(f'##### Example-{index+1}')
col1, col2 = st.columns([0.3, 0.7], vertical_alignment="center")
# with col1:
st.audio(f'{sample_folder}/sample_{index}.wav', format="audio/wav")
if dataset_name in ['CN-College-Listen-MCQ-Test', 'DREAM-TTS-MCQ-Test']:
choices = dataset[index]['other_attributes']['choices']
if isinstance(choices, str):
choices_text = choices
elif isinstance(choices, list):
choices_text = ' '.join(i for i in choices)
question_text = f"""{dataset[index]['instruction']['text']} {choices_text}"""
else:
question_text = f"""{dataset[index]['instruction']['text']}"""
question_text = html.escape(question_text)
# st.divider()
with st.container():
custom_css = """
<style>
.my-container-table, p.my-container-text {
background-color: #fcf8dc;
padding: 10px;
border-radius: 5px;
font-size: 13px;
# height: 50px;
word-wrap: break-word
}
</style>
"""
st.markdown(custom_css, unsafe_allow_html=True)
model_lists.sort()
s = f"""<tr>
<td><b>REFERENCE</td>
<td><b>{html.escape(question_text.replace('(A)', '<br>(A)').replace('(B)', '<br>(B)').replace('(C)', '<br>(C)'))}
</td>
<td><b>{html.escape(dataset[index]['answer']['text'])}
</td>
</tr>
"""
if dataset_name in ['CN-College-Listen-MCQ-Test', 'DREAM-TTS-MCQ-Test']:
for model in model_lists:
try:
model_prediction = dataset[index][model]['model_prediction']
model_prediction = model_prediction.replace('<','').replace('>','').replace('\n','(newline)').replace('*','')
s += f"""<tr>
<td>{display_model_names[model]}</td>
<td>
{dataset[index][model]['text'].replace('Choices:', '<br>Choices:').replace('(A)', '<br>(A)').replace('(B)', '<br>(B)').replace('(C)', '<br>(C)')
}
</td>
<td>{html.escape(model_prediction)}</td>
</tr>"""
except:
print(f"{model} is not in {dataset_name}")
continue
else:
for model in model_lists:
print(dataset[index][model]['model_prediction'])
try:
model_prediction = dataset[index][model]['model_prediction']
model_prediction = model_prediction.replace('<','').replace('>','').replace('\n','(newline)').replace('*','')
s += f"""<tr>
<td>{display_model_names[model]}</td>
<td>{html.escape(dataset[index][model]['text'])}</td>
<td>{html.escape(model_prediction)}</td>
</tr>"""
except:
print(f"{model} is not in {dataset_name}")
continue
body_details = f"""<table style="table-layout: fixed; width:100%">
<thead>
<tr style="text-align: center;">
<th style="width:20%">MODEL</th>
<th style="width:30%">QUESTION</th>
<th style="width:50%">MODEL PREDICTION</th>
</tr>
{s}
</thead>
</table>"""
st.markdown(f"""<div class="my-container-table">
{body_details}
</div>""", unsafe_allow_html=True)
st.text("")
st.divider()
|