Spaces:
Sleeping
Sleeping
File size: 9,964 Bytes
cab307f 512729d |
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 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 |
import json
import streamlit as st
import pandas as pd
import seaborn as sns
import plotly.graph_objects as go
import plotly.express as px
from st_social_media_links import SocialMediaIcons
AVERAGE_COLUMN_NAME = "Average"
SENTIMENT_COLUMN_NAME = "Sentiment"
RESULTS_COLUMN_NAME = "Results"
UNDERSTANDING_COLUMN_NAME = "Language understanding"
PHRASEOLOGY_COLUMN_NAME = "Phraseology"
# Function to load data from JSON file
def load_data(file_path):
with open(file_path, 'r', encoding='utf-8') as file:
data = json.load(file)
return pd.DataFrame(data)
# Function to style the DataFrame
def style_dataframe(df: pd.DataFrame):
df[RESULTS_COLUMN_NAME] = df.apply(lambda row: [row[SENTIMENT_COLUMN_NAME], row[UNDERSTANDING_COLUMN_NAME], row[PHRASEOLOGY_COLUMN_NAME]], axis=1)
# Insert the new column after the 'Average' column
cols = list(df.columns)
cols.insert(cols.index(AVERAGE_COLUMN_NAME) + 1, cols.pop(cols.index(RESULTS_COLUMN_NAME)))
df = df[cols]
# Create a color ramp using Seaborn
return df
def styler(df: pd.DataFrame):
palette = sns.color_palette("RdYlGn", as_cmap=True)
styled_df = df.style.background_gradient(cmap=palette, subset=[AVERAGE_COLUMN_NAME, SENTIMENT_COLUMN_NAME, PHRASEOLOGY_COLUMN_NAME, UNDERSTANDING_COLUMN_NAME]).format(precision=2)
return styled_df
### Streamlit app
st.set_page_config(layout="wide")
st.markdown("""
<style>
.block-container {
padding-top: 0%;
padding-bottom: 0%;
padding-left: 3%;
padding-right: 3%;
scrollbar-width: thin;
}
</style>
""", unsafe_allow_html=True)
### Prepare layout
st.subheader("")
st.markdown("""
<style>
.center {
display: block;
margin-left: auto;
margin-right: auto;
width: 50%;
}
.center-text {
text-align: center;
}
.table-responsive {
text-align: center;
font-size: 0.9em;
margin-left: 0%;
margin-right: 0%;
overflow-x: auto;
-ms-overflow-style: 3px; /* Internet Explorer 10+ */
scrollbar-width: thin; /* Firefox */
}
.table-responsive::-webkit-scrollbar {
/*display: none;*/ /* Safari and Chrome */
width: 6px;
}
#table_id {
display: block;
}
#table_id th {
display: inline-block;
}
#table_id td {
padding-left: 0.7rem;
padding-right: 0.7rem;
display: inline-block;
}
#table_id td:hover {
color:#FDA428;
}
a:link {color:#A85E00;} /* unvisited link */
a:hover {color:#FDA428;} /* Mouse over link */
a:visited {color:#A85E00;} /* visited link */
a:active {color:#A85E00;} /* selected link */
.image-container {
position: relative;
display: inline-block;
transition: transform 0.3s ease;
}
.image-container img {
vertical-align: middle;
}
.image-container::after {
content: "";
position: absolute;
left: 0;
bottom: 0;
width: 100%;
height: 2px;
background-color: #FDA428; /* Change this to your desired color */
transform: scaleX(0);
transition: transform 0.3s ease;
}
.image-container:hover {
transform: translateY(-3px); /* Change the value to adjust the upward movement */
}
.image-container:hover::after {
transform: scaleX(1);
}
/* ---------------------------------------------------------------- */
</style>
""", unsafe_allow_html=True)
# --- Colors info ---
# Primary Color: #FDA428
# Secondary Color: #A85E00
# Grey Color: #7B7B7B
# Background Color: #1C1C1C
# {'LOW': '#7B7B7B', 'MEDIUM': '#A85E00', 'HIGH': '#FDA428'}
# ----------------------------------------------------------
### Row: 1 --> Title + links to SpeakLeash.org website / GitHub / X (Twitter)
social_media_links = [
"https://discord.com/invite/ZJwCMrxwT7",
"https://github.com/speakleash",
"https://x.com/Speak_Leash",
"https://www.linkedin.com/company/speakleash/",
"https://www.facebook.com/Speakleash/"
]
social_media_links_colors = [
"#FFFFFF",
"#FFFFFF",
"#FFFFFF",
"#FFFFFF",
"#FFFFFF"
]
social_media_icons = SocialMediaIcons(social_media_links, social_media_links_colors)
social_media_icons.render(justify_content='right')
# Add logo, title, and subheader in a flexible container with equal spacing
st.markdown("""
<div class="header-container">
<img src="https://speakleash.org/wp-content/uploads/2023/09/SpeakLeash_logo.svg" alt="SpeakLeash Logo">
<hr>
<div class="title-container">
<h1 style='color: #FDA428; margin-top: -1rem; font-size: 3.1em;'>Phrase-Bench</h1>
<h3 style="margin-top: 0;">Understanding of Polish text, sentiment and phraseological compounds</h2>
</div>
</div>
""", unsafe_allow_html=True)
# Create tabs
tab1, tab2 = st.tabs([RESULTS_COLUMN_NAME, "Opis"])
with tab1:
st.write("This benchmark evaluates the ability of language models to correctly interpret Polish texts with complex implicatures, such as sarcasm and idiomatic expressions. Models are assessed on sentiment analysis, understanding of true intentions, and identification of idiomatic phrases.")
# Display the styled DataFrame
data = load_data('data.json')
data['Params'] = data['Params'].str.replace('B', '')
data = data.sort_values(by=AVERAGE_COLUMN_NAME, ascending=False)
styled_df_show = style_dataframe(data)
styled_df_show = styler(styled_df_show)
st.data_editor(styled_df_show, column_config={
"Params": st.column_config.NumberColumn("Params [B]", format="%.1f"),
AVERAGE_COLUMN_NAME: st.column_config.NumberColumn(AVERAGE_COLUMN_NAME),
RESULTS_COLUMN_NAME: st.column_config.BarChartColumn(
RESULTS_COLUMN_NAME, help="Summary of the results of each task",
y_min=0,y_max=5,),
SENTIMENT_COLUMN_NAME: st.column_config.NumberColumn(SENTIMENT_COLUMN_NAME, help='Ability to analyze sentiment'),
PHRASEOLOGY_COLUMN_NAME: st.column_config.NumberColumn(PHRASEOLOGY_COLUMN_NAME, help='Ability to understand phraseological compounds'),
UNDERSTANDING_COLUMN_NAME: st.column_config.NumberColumn(UNDERSTANDING_COLUMN_NAME, help='Ability to understand language'),
}, hide_index=True, disabled=True, height=500)
st.divider()
# Add selection for models and create a bar chart for selected models using the AVERAGE_COLUMN_NAME, SENTIMENT_COLUMN_NAME, PHRASEOLOGY_COLUMN_NAME, UNDERSTANDING_COLUMN_NAME
selected_models = st.multiselect("Select models to compare", data["Model"].unique())
selected_data = data[data["Model"].isin(selected_models)]
categories = [AVERAGE_COLUMN_NAME, SENTIMENT_COLUMN_NAME, PHRASEOLOGY_COLUMN_NAME, UNDERSTANDING_COLUMN_NAME]
if selected_models:
# Kolorki do wyboru:
# colors = px.colors.sample_colorscale("viridis", len(selected_models)+1)
colors = px.colors.qualitative.G10[:len(selected_models)]
# Create a chart with lines for each model for each category
fig = go.Figure()
for model, color in zip(selected_models, colors):
values = selected_data[selected_data['Model'] == model][categories].values.flatten().tolist()
values += values[:1] # Repeat the first value to close the polygon
fig.add_trace(go.Scatterpolar(
r=values,
theta=categories + [categories[0]], # Repeat the first category to close the polygon
name=model,
line_color=color,
fillcolor=color
))
fig.update_layout(
polar=dict(
radialaxis=dict(
visible=True,
range=[0, 5]
)),
showlegend=True,
legend=dict(orientation="h", yanchor="top", y=-0.2, xanchor="center", x=0.5),
title="Comparison of Selected Models",
template="plotly_dark"
)
st.plotly_chart(fig)
# Create a chart with bars for each model for each category
fig_bars = go.Figure()
for model, color in zip(selected_models, colors):
values = selected_data[selected_data['Model'] == model][categories].values.flatten().tolist()
fig_bars.add_trace(go.Bar(
x=categories,
y=values,
name=model,
marker_color=color
))
# Update layout to use a custom color scale
fig_bars.update_layout(
showlegend=True,
legend=dict(orientation="h", yanchor="top", y=-0.3, xanchor="center", x=0.5),
title="Comparison of Selected Models",
yaxis_title="Score",
template="plotly_dark"
)
st.plotly_chart(fig_bars)
with tab2:
st.header("Opis")
st.write("Tutaj znajduje się trochę tekstu jako wypełniacz.")
st.write("To jest przykładowy tekst, który może zawierać dodatkowe informacje o benchmarku, metodologii, itp.")
# Ending :)
st.divider()
st.markdown("""
### Authors:
- [Jan Sowa](https://www.linkedin.com/in/janpiotrsowa) - leadership, writing texts, benchmark code
- [Agnieszka Kosiak](https://www.linkedin.com/in/agn-kosiak/) - writing texts
- [Magdalena Krawczyk](https://www.linkedin.com/in/magdalena-krawczyk-7810942ab/) - writing texts, labeling
- [Remigiusz Kinas](https://www.linkedin.com/in/remigiusz-kinas/) - methodological support
- [Krzysztof Wróbel](https://www.linkedin.com/in/wrobelkrzysztof/) - engineering, methodological support
- [Szymon Baczyński](https://www.linkedin.com/in/szymon-baczynski/) - front-end / streamlit assistant
""")
# Run the app with `streamlit run your_script.py` |