Spaces:
Running
Running
File size: 5,639 Bytes
b0e6781 11356c3 b0e6781 11356c3 b0e6781 11356c3 b0e6781 11356c3 b0e6781 11356c3 b0e6781 |
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 |
import streamlit as st
import datasets
import numpy as np
def show_examples(category_name, dataset_name, model_lists):
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")
with col2:
with st.container():
custom_css = """
<style>
.my-container-question {
background-color: #F5EEF8;
padding: 10px;
border-radius: 10px;
height: auto;
}
</style>
"""
st.markdown(custom_css, unsafe_allow_html=True)
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"""<div class="my-container-question">
<p>QUESTION: {dataset[index]['instruction']['text']}</p>
<p>CHOICES: {choices_text}</p>
</div>
"""
else:
question_text = f"""<div class="my-container-question">
<p>QUESTION: {dataset[index]['instruction']['text']}</p>
</div>"""
st.markdown(question_text, unsafe_allow_html=True)
with st.container():
custom_css = """
<style>
.my-container-answer {
background-color: #F9EBEA;
padding: 10px;
border-radius: 10px;
height: auto;
}
</style>
"""
st.markdown(custom_css, unsafe_allow_html=True)
st.markdown(f"""<div class="my-container-answer">
<p>CORRECT ANSWER: {dataset[index]['answer']['text']}</p>
</div>""", unsafe_allow_html=True)
# st.divider()
with st.container():
custom_css = """
<style>
.my-container-table {
background-color: #F2F3F4;
padding: 10px;
border-radius: 5px;
# height: 50px;
}
</style>
"""
st.markdown(custom_css, unsafe_allow_html=True)
model_lists.sort()
s = ''
if dataset_name in ['CN-College-Listen-MCQ-Test', 'DREAM-TTS-MCQ-Test']:
for model in model_lists:
try:
s += f"""<tr>
<td>{model}</td>
<td><p>{dataset[index][model]['text']}</p> <p>{choices_text}</p></td>
<td>{dataset[index][model]['model_prediction']}</td>
</tr>"""
except:
print(f"{model} is not in {dataset_name}")
continue
else:
for model in model_lists:
try:
s += f"""<tr>
<td>{model}</td>
<td>{dataset[index][model]['text']}</td>
<td>{dataset[index][model]['model_prediction']}</td>
</tr>"""
except:
print(f"{model} is not in {dataset_name}")
continue
body_details = f"""<table style="width:100%">
<thead>
<tr style="text-align: center;">
<th style="width:20%">MODEL</th>
<th style="width:40%">QUESTION</th>
<th style="width:40%">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()
|