delete due to wrong path
Browse files- show_examples.py +0 -193
show_examples.py
DELETED
@@ -1,193 +0,0 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
import datasets
|
3 |
-
import numpy as np
|
4 |
-
|
5 |
-
import html
|
6 |
-
|
7 |
-
from app.content import displayname2datasetname
|
8 |
-
|
9 |
-
def show_dataset_examples(display_name):
|
10 |
-
st.divider()
|
11 |
-
dataset_name = displayname2datasetname[display_name]
|
12 |
-
sample_folder = f"./examples/{dataset_name}"
|
13 |
-
|
14 |
-
# load dataset
|
15 |
-
dataset = datasets.load_from_disk(sample_folder)
|
16 |
-
|
17 |
-
for index in range(len(dataset)):
|
18 |
-
with st.container():
|
19 |
-
st.markdown(f'##### Example-{index+1}')
|
20 |
-
col1, col2 = st.columns([0.3, 0.7], vertical_alignment="center")
|
21 |
-
|
22 |
-
# with col1:
|
23 |
-
st.audio(f'{sample_folder}/sample_{index}.wav', format="audio/wav")
|
24 |
-
|
25 |
-
if dataset_name in ['CN-College-Listen-MCQ-Test', 'DREAM-TTS-MCQ-Test']:
|
26 |
-
|
27 |
-
choices = dataset[index]['other_attributes']['choices']
|
28 |
-
if isinstance(choices, str):
|
29 |
-
choices_text = choices
|
30 |
-
elif isinstance(choices, list):
|
31 |
-
choices_text = ' '.join(i for i in choices)
|
32 |
-
|
33 |
-
question_text = f"""{dataset[index]['instruction']['text']} {choices_text}"""
|
34 |
-
else:
|
35 |
-
question_text = f"""{dataset[index]['instruction']['text']}"""
|
36 |
-
|
37 |
-
question_text = html.escape(question_text)
|
38 |
-
|
39 |
-
with st.container():
|
40 |
-
custom_css = """
|
41 |
-
<style>
|
42 |
-
.my-container-table, p.my-container-text {
|
43 |
-
background-color: #fcf8dc;
|
44 |
-
padding: 10px;
|
45 |
-
border-radius: 5px;
|
46 |
-
font-size: 13px;
|
47 |
-
# height: 50px;
|
48 |
-
word-wrap: break-word
|
49 |
-
}
|
50 |
-
</style>
|
51 |
-
"""
|
52 |
-
st.markdown(custom_css, unsafe_allow_html=True)
|
53 |
-
|
54 |
-
s = f"""<tr>
|
55 |
-
<td><b>{html.escape(question_text.replace('(A)', '<br>(A)').replace('(B)', '<br>(B)').replace('(C)', '<br>(C)'))}
|
56 |
-
</td>
|
57 |
-
<td><b>{html.escape(dataset[index]['answer']['text'])}
|
58 |
-
</td>
|
59 |
-
</tr>
|
60 |
-
"""
|
61 |
-
|
62 |
-
body_details = f"""<table style="table-layout: fixed; width:100%">
|
63 |
-
<thead>
|
64 |
-
<tr style="text-align: center;">
|
65 |
-
<th style="width:50%">PROMPT</th>
|
66 |
-
<th style="width:50%">ANSWER</th>
|
67 |
-
</tr>
|
68 |
-
{s}
|
69 |
-
</thead>
|
70 |
-
</table>"""
|
71 |
-
|
72 |
-
st.markdown(f"""<div class="my-container-table">
|
73 |
-
{body_details}
|
74 |
-
</div>""", unsafe_allow_html=True)
|
75 |
-
|
76 |
-
st.text("")
|
77 |
-
|
78 |
-
st.divider()
|
79 |
-
|
80 |
-
|
81 |
-
def show_examples(category_name, dataset_name, model_lists, display_model_names):
|
82 |
-
st.divider()
|
83 |
-
sample_folder = f"./examples/{category_name}/{dataset_name}"
|
84 |
-
|
85 |
-
dataset = datasets.load_from_disk(sample_folder)
|
86 |
-
|
87 |
-
for index in range(len(dataset)):
|
88 |
-
with st.container():
|
89 |
-
st.markdown(f'##### Example-{index+1}')
|
90 |
-
col1, col2 = st.columns([0.3, 0.7], vertical_alignment="center")
|
91 |
-
|
92 |
-
# with col1:
|
93 |
-
st.audio(f'{sample_folder}/sample_{index}.wav', format="audio/wav")
|
94 |
-
|
95 |
-
if dataset_name in ['CN-College-Listen-MCQ-Test', 'DREAM-TTS-MCQ-Test']:
|
96 |
-
|
97 |
-
choices = dataset[index]['other_attributes']['choices']
|
98 |
-
if isinstance(choices, str):
|
99 |
-
choices_text = choices
|
100 |
-
elif isinstance(choices, list):
|
101 |
-
choices_text = ' '.join(i for i in choices)
|
102 |
-
|
103 |
-
question_text = f"""{dataset[index]['instruction']['text']} {choices_text}"""
|
104 |
-
else:
|
105 |
-
question_text = f"""{dataset[index]['instruction']['text']}"""
|
106 |
-
|
107 |
-
question_text = html.escape(question_text)
|
108 |
-
|
109 |
-
# st.divider()
|
110 |
-
with st.container():
|
111 |
-
custom_css = """
|
112 |
-
<style>
|
113 |
-
.my-container-table, p.my-container-text {
|
114 |
-
background-color: #fcf8dc;
|
115 |
-
padding: 10px;
|
116 |
-
border-radius: 5px;
|
117 |
-
font-size: 13px;
|
118 |
-
# height: 50px;
|
119 |
-
word-wrap: break-word
|
120 |
-
}
|
121 |
-
</style>
|
122 |
-
"""
|
123 |
-
st.markdown(custom_css, unsafe_allow_html=True)
|
124 |
-
|
125 |
-
model_lists.sort()
|
126 |
-
|
127 |
-
s = f"""<tr>
|
128 |
-
<td><b>REFERENCE</td>
|
129 |
-
<td><b>{html.escape(question_text.replace('(A)', '<br>(A)').replace('(B)', '<br>(B)').replace('(C)', '<br>(C)'))}
|
130 |
-
</td>
|
131 |
-
<td><b>{html.escape(dataset[index]['answer']['text'])}
|
132 |
-
</td>
|
133 |
-
</tr>
|
134 |
-
"""
|
135 |
-
if dataset_name in ['CN-College-Listen-MCQ-Test', 'DREAM-TTS-MCQ-Test']:
|
136 |
-
for model in model_lists:
|
137 |
-
try:
|
138 |
-
|
139 |
-
model_prediction = dataset[index][model]['model_prediction']
|
140 |
-
model_prediction = model_prediction.replace('<','').replace('>','').replace('\n','(newline)').replace('*','')
|
141 |
-
|
142 |
-
s += f"""<tr>
|
143 |
-
<td>{display_model_names[model]}</td>
|
144 |
-
<td>
|
145 |
-
{dataset[index][model]['text'].replace('Choices:', '<br>Choices:').replace('(A)', '<br>(A)').replace('(B)', '<br>(B)').replace('(C)', '<br>(C)')
|
146 |
-
}
|
147 |
-
</td>
|
148 |
-
<td>{html.escape(model_prediction)}</td>
|
149 |
-
</tr>"""
|
150 |
-
except:
|
151 |
-
print(f"{model} is not in {dataset_name}")
|
152 |
-
continue
|
153 |
-
else:
|
154 |
-
for model in model_lists:
|
155 |
-
|
156 |
-
print(dataset[index][model]['model_prediction'])
|
157 |
-
|
158 |
-
try:
|
159 |
-
|
160 |
-
model_prediction = dataset[index][model]['model_prediction']
|
161 |
-
model_prediction = model_prediction.replace('<','').replace('>','').replace('\n','(newline)').replace('*','')
|
162 |
-
|
163 |
-
s += f"""<tr>
|
164 |
-
<td>{display_model_names[model]}</td>
|
165 |
-
<td>{html.escape(dataset[index][model]['text'])}</td>
|
166 |
-
<td>{html.escape(model_prediction)}</td>
|
167 |
-
</tr>"""
|
168 |
-
except:
|
169 |
-
print(f"{model} is not in {dataset_name}")
|
170 |
-
continue
|
171 |
-
|
172 |
-
|
173 |
-
body_details = f"""<table style="table-layout: fixed; width:100%">
|
174 |
-
<thead>
|
175 |
-
<tr style="text-align: center;">
|
176 |
-
<th style="width:20%">MODEL</th>
|
177 |
-
<th style="width:30%">QUESTION</th>
|
178 |
-
<th style="width:50%">MODEL PREDICTION</th>
|
179 |
-
</tr>
|
180 |
-
{s}
|
181 |
-
</thead>
|
182 |
-
</table>"""
|
183 |
-
|
184 |
-
st.markdown(f"""<div class="my-container-table">
|
185 |
-
{body_details}
|
186 |
-
</div>""", unsafe_allow_html=True)
|
187 |
-
|
188 |
-
st.text("")
|
189 |
-
|
190 |
-
st.divider()
|
191 |
-
|
192 |
-
|
193 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|