Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Commit
·
ccbe31d
1
Parent(s):
993d09a
refactor filtering from plotting with gr.State
Browse files
app.py
CHANGED
@@ -100,7 +100,7 @@ min_elo_score, max_elo_score, upper_models_per_month = get_constants(merged_dfs)
|
|
100 |
date_updated = elo_results["full"]["last_updated_datetime"].split(" ")[0]
|
101 |
|
102 |
###################
|
103 |
-
### Plot Data
|
104 |
###################
|
105 |
|
106 |
|
@@ -109,8 +109,7 @@ def get_data_split(dfs, set_name):
|
|
109 |
return df.reset_index(drop=True)
|
110 |
|
111 |
|
112 |
-
def
|
113 |
-
|
114 |
df = get_data_split(merged_dfs, set_name=set_selector)
|
115 |
|
116 |
# filter data
|
@@ -121,6 +120,10 @@ def build_plot(min_score, max_models_per_month, toggle_annotations, set_selector
|
|
121 |
.apply(lambda x: x.nlargest(max_models_per_month, "rating"))
|
122 |
.reset_index(drop=True)
|
123 |
)
|
|
|
|
|
|
|
|
|
124 |
|
125 |
# construct plot
|
126 |
custom_colors = {"Open": "#ff7f0e", "Proprietary": "#1f77b4"}
|
@@ -246,31 +249,37 @@ with gr.Blocks(
|
|
246 |
|
247 |
# Show plot
|
248 |
plot = gr.Plot()
|
|
|
|
|
249 |
demo.load(
|
250 |
-
fn=
|
251 |
-
inputs=[min_score, max_models_per_month,
|
252 |
-
outputs=
|
253 |
-
)
|
|
|
254 |
min_score.change(
|
255 |
-
fn=
|
256 |
-
inputs=[min_score, max_models_per_month,
|
257 |
-
outputs=
|
258 |
-
)
|
|
|
259 |
max_models_per_month.change(
|
260 |
-
fn=
|
261 |
-
inputs=[min_score, max_models_per_month,
|
262 |
-
outputs=
|
263 |
-
)
|
|
|
264 |
toggle_annotations.change(
|
265 |
-
fn=
|
266 |
-
inputs=[min_score, max_models_per_month,
|
267 |
-
outputs=
|
268 |
-
)
|
|
|
269 |
set_selector.change(
|
270 |
-
fn=
|
271 |
-
inputs=[min_score, max_models_per_month,
|
272 |
-
outputs=
|
273 |
-
)
|
274 |
|
275 |
gr.Markdown(
|
276 |
"""
|
|
|
100 |
date_updated = elo_results["full"]["last_updated_datetime"].split(" ")[0]
|
101 |
|
102 |
###################
|
103 |
+
### Build and Plot Data
|
104 |
###################
|
105 |
|
106 |
|
|
|
109 |
return df.reset_index(drop=True)
|
110 |
|
111 |
|
112 |
+
def filter_df(min_score, max_models_per_month, set_selector):
|
|
|
113 |
df = get_data_split(merged_dfs, set_name=set_selector)
|
114 |
|
115 |
# filter data
|
|
|
120 |
.apply(lambda x: x.nlargest(max_models_per_month, "rating"))
|
121 |
.reset_index(drop=True)
|
122 |
)
|
123 |
+
return filtered_df
|
124 |
+
|
125 |
+
|
126 |
+
def build_plot(toggle_annotations, filtered_df):
|
127 |
|
128 |
# construct plot
|
129 |
custom_colors = {"Open": "#ff7f0e", "Proprietary": "#1f77b4"}
|
|
|
249 |
|
250 |
# Show plot
|
251 |
plot = gr.Plot()
|
252 |
+
filtered_df = gr.State()
|
253 |
+
|
254 |
demo.load(
|
255 |
+
fn=filter_df,
|
256 |
+
inputs=[min_score, max_models_per_month, set_selector],
|
257 |
+
outputs=filtered_df,
|
258 |
+
).then(fn=build_plot, inputs=[toggle_annotations, filtered_df], outputs=plot)
|
259 |
+
|
260 |
min_score.change(
|
261 |
+
fn=filter_df,
|
262 |
+
inputs=[min_score, max_models_per_month, set_selector],
|
263 |
+
outputs=filtered_df,
|
264 |
+
).then(fn=build_plot, inputs=[toggle_annotations, filtered_df], outputs=plot)
|
265 |
+
|
266 |
max_models_per_month.change(
|
267 |
+
fn=filter_df,
|
268 |
+
inputs=[min_score, max_models_per_month, set_selector],
|
269 |
+
outputs=filtered_df,
|
270 |
+
).then(fn=build_plot, inputs=[toggle_annotations, filtered_df], outputs=plot)
|
271 |
+
|
272 |
toggle_annotations.change(
|
273 |
+
fn=filter_df,
|
274 |
+
inputs=[min_score, max_models_per_month, set_selector],
|
275 |
+
outputs=filtered_df,
|
276 |
+
).then(fn=build_plot, inputs=[toggle_annotations, filtered_df], outputs=plot)
|
277 |
+
|
278 |
set_selector.change(
|
279 |
+
fn=filter_df,
|
280 |
+
inputs=[min_score, max_models_per_month, set_selector],
|
281 |
+
outputs=filtered_df,
|
282 |
+
).then(fn=build_plot, inputs=[toggle_annotations, filtered_df], outputs=plot)
|
283 |
|
284 |
gr.Markdown(
|
285 |
"""
|