delete due to wrong path
Browse files- draw_diagram.py +0 -223
draw_diagram.py
DELETED
|
@@ -1,223 +0,0 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
-
import pandas as pd
|
| 3 |
-
import numpy as np
|
| 4 |
-
from streamlit_echarts import st_echarts
|
| 5 |
-
from app.show_examples import *
|
| 6 |
-
from app.content import *
|
| 7 |
-
|
| 8 |
-
import pandas as pd
|
| 9 |
-
|
| 10 |
-
from model_information import get_dataframe
|
| 11 |
-
info_df = get_dataframe()
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
def draw(folder_name, category_name, displayname, metrics, cus_sort=True):
|
| 15 |
-
|
| 16 |
-
folder = f"./results_organized/{metrics}/"
|
| 17 |
-
|
| 18 |
-
# Load the results from CSV
|
| 19 |
-
data_path = f'{folder}/{category_name.lower()}.csv'
|
| 20 |
-
chart_data = pd.read_csv(data_path).round(3)
|
| 21 |
-
|
| 22 |
-
dataset_name = displayname2datasetname[displayname]
|
| 23 |
-
chart_data = chart_data[['Model', dataset_name]]
|
| 24 |
-
|
| 25 |
-
# Rename to proper display name
|
| 26 |
-
chart_data = chart_data.rename(columns=datasetname2diaplayname)
|
| 27 |
-
|
| 28 |
-
st.markdown("""
|
| 29 |
-
<style>
|
| 30 |
-
.stMultiSelect [data-baseweb=select] span {
|
| 31 |
-
max-width: 800px;
|
| 32 |
-
font-size: 0.9rem;
|
| 33 |
-
background-color: #3C6478 !important; /* Background color for selected items */
|
| 34 |
-
color: white; /* Change text color */
|
| 35 |
-
back
|
| 36 |
-
}
|
| 37 |
-
</style>
|
| 38 |
-
""", unsafe_allow_html=True)
|
| 39 |
-
|
| 40 |
-
# remap model names
|
| 41 |
-
display_model_names = {key.strip() :val.strip() for key, val in zip(info_df['Original Name'], info_df['Proper Display Name'])}
|
| 42 |
-
chart_data['model_show'] = chart_data['Model'].map(lambda x: display_model_names.get(x, x))
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
models = st.multiselect("Please choose the model",
|
| 46 |
-
sorted(chart_data['model_show'].tolist()),
|
| 47 |
-
default = sorted(chart_data['model_show'].tolist()),
|
| 48 |
-
)
|
| 49 |
-
|
| 50 |
-
chart_data = chart_data[chart_data['model_show'].isin(models)]
|
| 51 |
-
chart_data = chart_data.sort_values(by=[displayname], ascending=cus_sort).dropna(axis=0)
|
| 52 |
-
|
| 53 |
-
if len(chart_data) == 0: return
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
# = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
|
| 57 |
-
'''
|
| 58 |
-
Show Table
|
| 59 |
-
'''
|
| 60 |
-
with st.container():
|
| 61 |
-
st.markdown('##### TABLE')
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
model_link = {key.strip(): val for key, val in zip(info_df['Proper Display Name'], info_df['Link'])}
|
| 65 |
-
|
| 66 |
-
chart_data['model_link'] = chart_data['model_show'].map(model_link)
|
| 67 |
-
|
| 68 |
-
chart_data_table = chart_data[['model_show', chart_data.columns[1], chart_data.columns[3]]]
|
| 69 |
-
|
| 70 |
-
# Format numeric columns to 2 decimal places
|
| 71 |
-
#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))
|
| 72 |
-
cur_dataset_name = chart_data_table.columns[1]
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
def highlight_first_element(x):
|
| 76 |
-
# Create a DataFrame with the same shape as the input
|
| 77 |
-
df_style = pd.DataFrame('', index=x.index, columns=x.columns)
|
| 78 |
-
# Apply background color to the first element in row 0 (df[0][0])
|
| 79 |
-
# df_style.iloc[0, 1] = 'background-color: #b0c1d7; color: white'
|
| 80 |
-
df_style.iloc[0, 1] = 'background-color: #b0c1d7'
|
| 81 |
-
|
| 82 |
-
return df_style
|
| 83 |
-
|
| 84 |
-
if cur_dataset_name in [
|
| 85 |
-
'LibriSpeech-Clean',
|
| 86 |
-
'LibriSpeech-Other',
|
| 87 |
-
'CommonVoice-15-EN',
|
| 88 |
-
'Peoples-Speech',
|
| 89 |
-
'GigaSpeech-1',
|
| 90 |
-
'Earnings-21',
|
| 91 |
-
'Earnings-22',
|
| 92 |
-
'TED-LIUM-3',
|
| 93 |
-
'TED-LIUM-3-LongForm',
|
| 94 |
-
'AISHELL-ASR-ZH',
|
| 95 |
-
'MNSC-PART1-ASR',
|
| 96 |
-
'MNSC-PART2-ASR',
|
| 97 |
-
'MNSC-PART3-ASR',
|
| 98 |
-
'MNSC-PART4-ASR',
|
| 99 |
-
'MNSC-PART5-ASR',
|
| 100 |
-
'MNSC-PART6-ASR',
|
| 101 |
-
'CNA',
|
| 102 |
-
'IDPC',
|
| 103 |
-
'Parliament',
|
| 104 |
-
'UKUS-News',
|
| 105 |
-
'Mediacorp',
|
| 106 |
-
'IDPC-Short',
|
| 107 |
-
'Parliament-Short',
|
| 108 |
-
'UKUS-News-Short',
|
| 109 |
-
'Mediacorp-Short',
|
| 110 |
-
'YTB-ASR-Batch1',
|
| 111 |
-
'YTB-ASR-Batch2',
|
| 112 |
-
'SEAME-Dev-Man',
|
| 113 |
-
'SEAME-Dev-Sge',
|
| 114 |
-
]:
|
| 115 |
-
|
| 116 |
-
chart_data_table = chart_data_table.sort_values(
|
| 117 |
-
by=chart_data_table.columns[1],
|
| 118 |
-
ascending=True
|
| 119 |
-
).reset_index(drop=True)
|
| 120 |
-
else:
|
| 121 |
-
chart_data_table = chart_data_table.sort_values(
|
| 122 |
-
by=chart_data_table.columns[1],
|
| 123 |
-
ascending=False
|
| 124 |
-
).reset_index(drop=True)
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
styled_df = chart_data_table.style.format(
|
| 128 |
-
{chart_data_table.columns[1]: "{:.3f}"}
|
| 129 |
-
).apply(
|
| 130 |
-
highlight_first_element, axis=None
|
| 131 |
-
)
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
st.dataframe(
|
| 135 |
-
styled_df,
|
| 136 |
-
column_config={
|
| 137 |
-
'model_show': 'Model',
|
| 138 |
-
chart_data_table.columns[1]: {'alignment': 'left'},
|
| 139 |
-
"model_link": st.column_config.LinkColumn(
|
| 140 |
-
"Model Link",
|
| 141 |
-
),
|
| 142 |
-
},
|
| 143 |
-
hide_index=True,
|
| 144 |
-
use_container_width=True
|
| 145 |
-
)
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
# = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
|
| 149 |
-
'''
|
| 150 |
-
Show Chart
|
| 151 |
-
'''
|
| 152 |
-
|
| 153 |
-
# Initialize a session state variable for toggling the chart visibility
|
| 154 |
-
if "show_chart" not in st.session_state:
|
| 155 |
-
st.session_state.show_chart = False
|
| 156 |
-
|
| 157 |
-
# Create a button to toggle visibility
|
| 158 |
-
if st.button("Show Chart"):
|
| 159 |
-
st.session_state.show_chart = not st.session_state.show_chart
|
| 160 |
-
|
| 161 |
-
if st.session_state.show_chart:
|
| 162 |
-
|
| 163 |
-
with st.container():
|
| 164 |
-
st.markdown('##### CHART')
|
| 165 |
-
|
| 166 |
-
# Get Values
|
| 167 |
-
data_values = chart_data.iloc[:, 1]
|
| 168 |
-
|
| 169 |
-
# Calculate Q1 and Q3
|
| 170 |
-
q1 = data_values.quantile(0.25)
|
| 171 |
-
q3 = data_values.quantile(0.75)
|
| 172 |
-
|
| 173 |
-
# Calculate IQR
|
| 174 |
-
iqr = q3 - q1
|
| 175 |
-
|
| 176 |
-
# Define lower and upper bounds (1.5*IQR is a common threshold)
|
| 177 |
-
lower_bound = q1 - 1.5 * iqr
|
| 178 |
-
upper_bound = q3 + 1.5 * iqr
|
| 179 |
-
|
| 180 |
-
# Filter data within the bounds
|
| 181 |
-
filtered_data = data_values[(data_values >= lower_bound) & (data_values <= upper_bound)]
|
| 182 |
-
|
| 183 |
-
# Calculate min and max values after outlier handling
|
| 184 |
-
min_value = round(filtered_data.min() - 0.1 * filtered_data.min(), 3)
|
| 185 |
-
max_value = round(filtered_data.max() + 0.1 * filtered_data.max(), 3)
|
| 186 |
-
|
| 187 |
-
options = {
|
| 188 |
-
# "title": {"text": f"{dataset_name}"},
|
| 189 |
-
"tooltip": {
|
| 190 |
-
"trigger": "axis",
|
| 191 |
-
"axisPointer": {"type": "cross", "label": {"backgroundColor": "#6a7985"}},
|
| 192 |
-
"triggerOn": 'mousemove',
|
| 193 |
-
},
|
| 194 |
-
"legend": {"data": ['Overall Accuracy']},
|
| 195 |
-
"toolbox": {"feature": {"saveAsImage": {}}},
|
| 196 |
-
"grid": {"left": "3%", "right": "4%", "bottom": "3%", "containLabel": True},
|
| 197 |
-
"xAxis": [
|
| 198 |
-
{
|
| 199 |
-
"type": "category",
|
| 200 |
-
"boundaryGap": True,
|
| 201 |
-
"triggerEvent": True,
|
| 202 |
-
"data": chart_data['model_show'].tolist(),
|
| 203 |
-
}
|
| 204 |
-
],
|
| 205 |
-
"yAxis": [{"type": "value",
|
| 206 |
-
"min": min_value,
|
| 207 |
-
"max": max_value,
|
| 208 |
-
"boundaryGap": True
|
| 209 |
-
# "splitNumber": 10
|
| 210 |
-
}],
|
| 211 |
-
"series": [{
|
| 212 |
-
"name": f"{dataset_name}",
|
| 213 |
-
"type": "bar",
|
| 214 |
-
"data": chart_data[f'{displayname}'].tolist(),
|
| 215 |
-
}],
|
| 216 |
-
}
|
| 217 |
-
|
| 218 |
-
events = {
|
| 219 |
-
"click": "function(params) { return params.value }"
|
| 220 |
-
}
|
| 221 |
-
|
| 222 |
-
value = st_echarts(options=options, events=events, height="500px")
|
| 223 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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