SamoXXX commited on
Commit
cab307f
1 Parent(s): 710ce9e

Visuals and charts

Browse files
Files changed (1) hide show
  1. app.py +278 -121
app.py CHANGED
@@ -1,122 +1,279 @@
1
- import json
2
- import streamlit as st
3
- import pandas as pd
4
- import seaborn as sns
5
- from st_social_media_links import SocialMediaIcons
6
-
7
- AVERAGE_COLUMN_NAME = "Average"
8
- SENTIMENT_COLUMN_NAME = "Sentiment"
9
- RESULTS_COLUMN_NAME = "Results"
10
- UNDERSTANDING_COLUMN_NAME = "Language understanding"
11
- PHRASEOLOGY_COLUMN_NAME = "Phraseology"
12
-
13
- # Function to load data from JSON file
14
- def load_data(file_path):
15
- with open(file_path, 'r', encoding='utf-8') as file:
16
- data = json.load(file)
17
- return pd.DataFrame(data)
18
-
19
- # Function to style the DataFrame
20
- def style_dataframe(df: pd.DataFrame):
21
- df[RESULTS_COLUMN_NAME] = df.apply(lambda row: [row[SENTIMENT_COLUMN_NAME], row[UNDERSTANDING_COLUMN_NAME], row[PHRASEOLOGY_COLUMN_NAME]], axis=1)
22
-
23
- # Insert the new column after the 'Average' column
24
- cols = list(df.columns)
25
- cols.insert(cols.index(AVERAGE_COLUMN_NAME) + 1, cols.pop(cols.index(RESULTS_COLUMN_NAME)))
26
- df = df[cols]
27
-
28
- # Create a color ramp using Seaborn
29
- return df
30
-
31
- def styler(df: pd.DataFrame):
32
- palette = sns.color_palette("RdYlGn", as_cmap=True)
33
- styled_df = df.style.background_gradient(cmap=palette, subset=[AVERAGE_COLUMN_NAME, SENTIMENT_COLUMN_NAME, PHRASEOLOGY_COLUMN_NAME, UNDERSTANDING_COLUMN_NAME]).format(precision=2)
34
- return styled_df
35
-
36
- # Load data from JSON file
37
- data = load_data('data.json')
38
-
39
-
40
- # Streamlit app
41
- st.set_page_config(layout="wide")
42
- st.markdown("""
43
- <style>
44
- .block-container {
45
- padding-top: 3%;
46
- padding-bottom: 1%;
47
- padding-left: 10%;
48
- padding-right: 10%;
49
- scrollbar-width: thin;
50
- }
51
- .header-container {
52
- display: flex;
53
- justify-content: space-around; /* Evenly distribute space between elements */
54
- }
55
- @media (max-width: 768px) {
56
- .header-container {
57
- flex-direction: column;
58
- align-items: center; /* Center the items vertically on smaller screens */
59
- width: 100%;
60
- }
61
- }
62
- </style>
63
- """, unsafe_allow_html=True)
64
-
65
- # Add logo, title, and subheader in a flexible container with equal spacing
66
- st.markdown("""
67
- <div class="header-container">
68
- <img src="https://speakleash.org/wp-content/uploads/2023/09/SpeakLeash_logo.svg" alt="SpeakLeash Logo">
69
- <div class="title-container">
70
- <h1>SpeakLeash-Bench</h1>
71
- <h3 style="margin-top: 0;">Understanding of Polish text, sentiment and phraseological compounds</h2>
72
- </div>
73
- </div>
74
- """, unsafe_allow_html=True)
75
-
76
- # Create tabs
77
- tab1, tab2 = st.tabs([RESULTS_COLUMN_NAME, "Opis"])
78
-
79
- with tab1:
80
- 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.")
81
-
82
- # Display the styled DataFrame
83
- styled_df_show = style_dataframe(data)
84
- styled_df_show = styler(styled_df_show)
85
-
86
- st.data_editor(styled_df_show, column_config={
87
- AVERAGE_COLUMN_NAME: st.column_config.NumberColumn(AVERAGE_COLUMN_NAME),
88
- RESULTS_COLUMN_NAME: st.column_config.BarChartColumn(
89
- RESULTS_COLUMN_NAME, help="Summary of the results of each task",
90
- y_min=0,y_max=5,),
91
- SENTIMENT_COLUMN_NAME: st.column_config.NumberColumn(SENTIMENT_COLUMN_NAME, help='Ability to analyze sentiment'),
92
- PHRASEOLOGY_COLUMN_NAME: st.column_config.NumberColumn(PHRASEOLOGY_COLUMN_NAME, help='Ability to understand phraseological compounds'),
93
- UNDERSTANDING_COLUMN_NAME: st.column_config.NumberColumn(UNDERSTANDING_COLUMN_NAME, help='Ability to understand language'),
94
- }, hide_index=True, disabled=True, height=500)
95
-
96
- st.markdown("""
97
- ### Authors:
98
- - [Jan Sowa](https://www.linkedin.com/in/janpiotrsowa) - leadership, writing texts, benchmark code
99
- - [Agnieszka Kosiak](https://www.linkedin.com/in/agn-kosiak/) - writing texts
100
- - [Magdalena Krawczyk](https://www.linkedin.com/in/magdalena-krawczyk-7810942ab/) - writing texts, labeling
101
- - [Remigiusz Kinas](https://www.linkedin.com/in/remigiusz-kinas/) - methodological support
102
- - [Krzysztof Wróbel](https://www.linkedin.com/in/wrobelkrzysztof/) - engineering, methodological support
103
- """)
104
-
105
- with tab2:
106
- st.header("Opis")
107
- st.write("Tutaj znajduje się trochę tekstu jako wypełniacz.")
108
- st.write("To jest przykładowy tekst, który może zawierać dodatkowe informacje o benchmarku, metodologii, itp.")
109
-
110
- social_media_links = [
111
- "https://discord.com/invite/ZJwCMrxwT7",
112
- "https://www.linkedin.com/company/speakleash/",
113
- "https://github.com/speakleash",
114
- "https://x.com/Speak_Leash",
115
- "https://www.facebook.com/Speakleash/"
116
- ]
117
-
118
- social_media_icons = SocialMediaIcons(social_media_links)
119
-
120
- social_media_icons.render()
121
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
122
  # Run the app with `streamlit run your_script.py`
 
1
+ import json
2
+ import streamlit as st
3
+ import pandas as pd
4
+ import seaborn as sns
5
+ import plotly.graph_objects as go
6
+ import plotly.express as px
7
+ from st_social_media_links import SocialMediaIcons
8
+
9
+ AVERAGE_COLUMN_NAME = "Average"
10
+ SENTIMENT_COLUMN_NAME = "Sentiment"
11
+ RESULTS_COLUMN_NAME = "Results"
12
+ UNDERSTANDING_COLUMN_NAME = "Language understanding"
13
+ PHRASEOLOGY_COLUMN_NAME = "Phraseology"
14
+
15
+ # Function to load data from JSON file
16
+ def load_data(file_path):
17
+ with open(file_path, 'r', encoding='utf-8') as file:
18
+ data = json.load(file)
19
+ return pd.DataFrame(data)
20
+
21
+ # Function to style the DataFrame
22
+ def style_dataframe(df: pd.DataFrame):
23
+ df[RESULTS_COLUMN_NAME] = df.apply(lambda row: [row[SENTIMENT_COLUMN_NAME], row[UNDERSTANDING_COLUMN_NAME], row[PHRASEOLOGY_COLUMN_NAME]], axis=1)
24
+
25
+ # Insert the new column after the 'Average' column
26
+ cols = list(df.columns)
27
+ cols.insert(cols.index(AVERAGE_COLUMN_NAME) + 1, cols.pop(cols.index(RESULTS_COLUMN_NAME)))
28
+ df = df[cols]
29
+
30
+ # Create a color ramp using Seaborn
31
+ return df
32
+
33
+ def styler(df: pd.DataFrame):
34
+ palette = sns.color_palette("RdYlGn", as_cmap=True)
35
+ styled_df = df.style.background_gradient(cmap=palette, subset=[AVERAGE_COLUMN_NAME, SENTIMENT_COLUMN_NAME, PHRASEOLOGY_COLUMN_NAME, UNDERSTANDING_COLUMN_NAME]).format(precision=2)
36
+ return styled_df
37
+
38
+
39
+ ### Streamlit app
40
+ st.set_page_config(layout="wide")
41
+
42
+ st.markdown("""
43
+ <style>
44
+ .block-container {
45
+ padding-top: 0%;
46
+ padding-bottom: 0%;
47
+ padding-left: 3%;
48
+ padding-right: 3%;
49
+ scrollbar-width: thin;
50
+ }
51
+ </style>
52
+ """, unsafe_allow_html=True)
53
+
54
+ ### Prepare layout
55
+ st.subheader("")
56
+
57
+ st.markdown("""
58
+ <style>
59
+ .center {
60
+ display: block;
61
+ margin-left: auto;
62
+ margin-right: auto;
63
+ width: 50%;
64
+ }
65
+ .center-text {
66
+ text-align: center;
67
+ }
68
+ .table-responsive {
69
+ text-align: center;
70
+ font-size: 0.9em;
71
+ margin-left: 0%;
72
+ margin-right: 0%;
73
+ overflow-x: auto;
74
+ -ms-overflow-style: 3px; /* Internet Explorer 10+ */
75
+ scrollbar-width: thin; /* Firefox */
76
+ }
77
+ .table-responsive::-webkit-scrollbar {
78
+ /*display: none;*/ /* Safari and Chrome */
79
+ width: 6px;
80
+ }
81
+
82
+ #table_id {
83
+ display: block;
84
+ }
85
+
86
+ #table_id th {
87
+ display: inline-block;
88
+ }
89
+
90
+ #table_id td {
91
+ padding-left: 0.7rem;
92
+ padding-right: 0.7rem;
93
+ display: inline-block;
94
+ }
95
+ #table_id td:hover {
96
+ color:#FDA428;
97
+ }
98
+
99
+ a:link {color:#A85E00;} /* unvisited link */
100
+ a:hover {color:#FDA428;} /* Mouse over link */
101
+ a:visited {color:#A85E00;} /* visited link */
102
+ a:active {color:#A85E00;} /* selected link */
103
+
104
+ .image-container {
105
+ position: relative;
106
+ display: inline-block;
107
+ transition: transform 0.3s ease;
108
+ }
109
+
110
+ .image-container img {
111
+ vertical-align: middle;
112
+ }
113
+
114
+ .image-container::after {
115
+ content: "";
116
+ position: absolute;
117
+ left: 0;
118
+ bottom: 0;
119
+ width: 100%;
120
+ height: 2px;
121
+ background-color: #FDA428; /* Change this to your desired color */
122
+ transform: scaleX(0);
123
+ transition: transform 0.3s ease;
124
+ }
125
+
126
+ .image-container:hover {
127
+ transform: translateY(-3px); /* Change the value to adjust the upward movement */
128
+ }
129
+
130
+ .image-container:hover::after {
131
+ transform: scaleX(1);
132
+ }
133
+
134
+ /* ---------------------------------------------------------------- */
135
+ </style>
136
+ """, unsafe_allow_html=True)
137
+
138
+ # --- Colors info ---
139
+ # Primary Color: #FDA428
140
+ # Secondary Color: #A85E00
141
+ # Grey Color: #7B7B7B
142
+ # Background Color: #1C1C1C
143
+ # {'LOW': '#7B7B7B', 'MEDIUM': '#A85E00', 'HIGH': '#FDA428'}
144
+ # ----------------------------------------------------------
145
+
146
+ ### Row: 1 --> Title + links to SpeakLeash.org website / GitHub / X (Twitter)
147
+ social_media_links = [
148
+ "https://discord.com/invite/ZJwCMrxwT7",
149
+ "https://github.com/speakleash",
150
+ "https://x.com/Speak_Leash",
151
+ "https://www.linkedin.com/company/speakleash/",
152
+ "https://www.facebook.com/Speakleash/"
153
+ ]
154
+
155
+ social_media_links_colors = [
156
+ "#FFFFFF",
157
+ "#FFFFFF",
158
+ "#FFFFFF",
159
+ "#FFFFFF",
160
+ "#FFFFFF"
161
+ ]
162
+
163
+ social_media_icons = SocialMediaIcons(social_media_links, social_media_links_colors)
164
+ social_media_icons.render(justify_content='right')
165
+
166
+ # Add logo, title, and subheader in a flexible container with equal spacing
167
+ st.markdown("""
168
+ <div class="header-container">
169
+ <img src="https://speakleash.org/wp-content/uploads/2023/09/SpeakLeash_logo.svg" alt="SpeakLeash Logo">
170
+ <hr>
171
+ <div class="title-container">
172
+ <h1 style='color: #FDA428; margin-top: -1rem; font-size: 3.1em;'>Phrase-Bench</h1>
173
+ <h3 style="margin-top: 0;">Understanding of Polish text, sentiment and phraseological compounds</h2>
174
+ </div>
175
+ </div>
176
+ """, unsafe_allow_html=True)
177
+
178
+ # Create tabs
179
+ tab1, tab2 = st.tabs([RESULTS_COLUMN_NAME, "Opis"])
180
+
181
+ with tab1:
182
+ 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.")
183
+
184
+ # Display the styled DataFrame
185
+ data = load_data('data.json')
186
+ data['Params'] = data['Params'].str.replace('B', '')
187
+ data = data.sort_values(by=AVERAGE_COLUMN_NAME, ascending=False)
188
+ styled_df_show = style_dataframe(data)
189
+ styled_df_show = styler(styled_df_show)
190
+
191
+ st.data_editor(styled_df_show, column_config={
192
+ "Params": st.column_config.NumberColumn("Params [B]", format="%.1f"),
193
+ AVERAGE_COLUMN_NAME: st.column_config.NumberColumn(AVERAGE_COLUMN_NAME),
194
+ RESULTS_COLUMN_NAME: st.column_config.BarChartColumn(
195
+ RESULTS_COLUMN_NAME, help="Summary of the results of each task",
196
+ y_min=0,y_max=5,),
197
+ SENTIMENT_COLUMN_NAME: st.column_config.NumberColumn(SENTIMENT_COLUMN_NAME, help='Ability to analyze sentiment'),
198
+ PHRASEOLOGY_COLUMN_NAME: st.column_config.NumberColumn(PHRASEOLOGY_COLUMN_NAME, help='Ability to understand phraseological compounds'),
199
+ UNDERSTANDING_COLUMN_NAME: st.column_config.NumberColumn(UNDERSTANDING_COLUMN_NAME, help='Ability to understand language'),
200
+ }, hide_index=True, disabled=True, height=500)
201
+
202
+ st.divider()
203
+
204
+ # 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
205
+ selected_models = st.multiselect("Select models to compare", data["Model"].unique())
206
+ selected_data = data[data["Model"].isin(selected_models)]
207
+ categories = [AVERAGE_COLUMN_NAME, SENTIMENT_COLUMN_NAME, PHRASEOLOGY_COLUMN_NAME, UNDERSTANDING_COLUMN_NAME]
208
+
209
+ if selected_models:
210
+ # Kolorki do wyboru:
211
+ # colors = px.colors.sample_colorscale("viridis", len(selected_models)+1)
212
+ colors = px.colors.qualitative.G10[:len(selected_models)]
213
+
214
+ # Create a chart with lines for each model for each category
215
+ fig = go.Figure()
216
+ for model, color in zip(selected_models, colors):
217
+ values = selected_data[selected_data['Model'] == model][categories].values.flatten().tolist()
218
+ values += values[:1] # Repeat the first value to close the polygon
219
+
220
+ fig.add_trace(go.Scatterpolar(
221
+ r=values,
222
+ theta=categories + [categories[0]], # Repeat the first category to close the polygon
223
+ name=model,
224
+ line_color=color,
225
+ fillcolor=color
226
+ ))
227
+
228
+ fig.update_layout(
229
+ polar=dict(
230
+ radialaxis=dict(
231
+ visible=True,
232
+ range=[0, 5]
233
+ )),
234
+ showlegend=True,
235
+ legend=dict(orientation="h", yanchor="top", y=-0.2, xanchor="center", x=0.5),
236
+ title="Comparison of Selected Models",
237
+ template="plotly_dark"
238
+ )
239
+ st.plotly_chart(fig)
240
+
241
+ # Create a chart with bars for each model for each category
242
+ fig_bars = go.Figure()
243
+ for model, color in zip(selected_models, colors):
244
+ values = selected_data[selected_data['Model'] == model][categories].values.flatten().tolist()
245
+ fig_bars.add_trace(go.Bar(
246
+ x=categories,
247
+ y=values,
248
+ name=model,
249
+ marker_color=color
250
+ ))
251
+
252
+ # Update layout to use a custom color scale
253
+ fig_bars.update_layout(
254
+ showlegend=True,
255
+ legend=dict(orientation="h", yanchor="top", y=-0.3, xanchor="center", x=0.5),
256
+ title="Comparison of Selected Models",
257
+ yaxis_title="Score",
258
+ template="plotly_dark"
259
+ )
260
+ st.plotly_chart(fig_bars)
261
+
262
+ with tab2:
263
+ st.header("Opis")
264
+ st.write("Tutaj znajduje się trochę tekstu jako wypełniacz.")
265
+ st.write("To jest przykładowy tekst, który może zawierać dodatkowe informacje o benchmarku, metodologii, itp.")
266
+
267
+
268
+ # Ending :)
269
+ st.divider()
270
+ st.markdown("""
271
+ ### Authors:
272
+ - [Jan Sowa](https://www.linkedin.com/in/janpiotrsowa) - leadership, writing texts, benchmark code
273
+ - [Agnieszka Kosiak](https://www.linkedin.com/in/agn-kosiak/) - writing texts
274
+ - [Magdalena Krawczyk](https://www.linkedin.com/in/magdalena-krawczyk-7810942ab/) - writing texts, labeling
275
+ - [Remigiusz Kinas](https://www.linkedin.com/in/remigiusz-kinas/) - methodological support
276
+ - [Krzysztof Wróbel](https://www.linkedin.com/in/wrobelkrzysztof/) - engineering, methodological support
277
+ - [Szymon Baczyński](https://www.linkedin.com/in/szymon-baczynski/) - front-end / streamlit assistant
278
+ """)
279
  # Run the app with `streamlit run your_script.py`