Spaces:
Build error
Build error
Commit
·
65393ab
1
Parent(s):
306970a
Use multiple dfs to make functions run in parallel
Browse files- gradio_function.py +3 -0
- pitcher_dashboard.py +27 -8
gradio_function.py
CHANGED
|
@@ -39,6 +39,9 @@ def clone_df(fn):
|
|
| 39 |
return fn(*args, **kwargs)
|
| 40 |
return _fn
|
| 41 |
|
|
|
|
|
|
|
|
|
|
| 42 |
# location maps
|
| 43 |
def fit_pred_kde(data, X, Y):
|
| 44 |
kde = gaussian_kde(data)
|
|
|
|
| 39 |
return fn(*args, **kwargs)
|
| 40 |
return _fn
|
| 41 |
|
| 42 |
+
def copy_dataframe(df, num_copy_to):
|
| 43 |
+
return [df.clone() for _ in range(num_copy_to)]
|
| 44 |
+
|
| 45 |
# location maps
|
| 46 |
def fit_pred_kde(data, X, Y):
|
| 47 |
kde = gaussian_kde(data)
|
pitcher_dashboard.py
CHANGED
|
@@ -78,6 +78,19 @@ def create_pitcher_dashboard():
|
|
| 78 |
pitch_velos.append(gr.Plot(show_label=False, elem_classes='pitch-velo', visible=visible))
|
| 79 |
pitch_locs.append(gr.Plot(label='Pitch Location', elem_classes='pitch-loc', visible=visible))
|
| 80 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
(
|
| 82 |
player
|
| 83 |
.input(update_dfs, inputs=[player, handedness, source_df], outputs=[app_df, app_league_df, app_pitch_stats, app_league_pitch_stats])
|
|
@@ -93,14 +106,20 @@ def create_pitcher_dashboard():
|
|
| 93 |
# app_df.change(plot_pitch_cards, inputs=[app_df, app_pitch_stats], outputs=pitch_rows+pitch_groups+pitch_names+pitch_infos+pitch_velos+pitch_locs)
|
| 94 |
app_pitch_stats.change(update_velo_stats, inputs=[app_pitch_stats, app_league_pitch_stats], outputs=velo_stats)
|
| 95 |
|
| 96 |
-
(
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
|
| 105 |
gr.Markdown('## Bugs and other notes')
|
| 106 |
with gr.Accordion('Click to open', open=False):
|
|
|
|
| 78 |
pitch_velos.append(gr.Plot(show_label=False, elem_classes='pitch-velo', visible=visible))
|
| 79 |
pitch_locs.append(gr.Plot(label='Pitch Location', elem_classes='pitch-loc', visible=visible))
|
| 80 |
|
| 81 |
+
download_file_fn = create_set_download_file_fn('files/player.csv')
|
| 82 |
+
plot_loc_summary = lambda df: plot_loc(df)
|
| 83 |
+
fn_configs = {
|
| 84 |
+
download_file_fn: dict(inputs=[], outputs=download_file),
|
| 85 |
+
plot_usage: dict(inputs=[player], outputs=usage),
|
| 86 |
+
plot_velo_summary: dict(inputs=[app_league_df, player], outputs=velo_summary),
|
| 87 |
+
plot_loc_summary: dict(inputs=[], outputs=loc_summary),
|
| 88 |
+
plot_pitch_cards: dict(inputs=[app_league_df, app_pitch_stats], outputs=pitch_rows+pitch_groups+pitch_names+pitch_infos+pitch_velos+pitch_locs)
|
| 89 |
+
}
|
| 90 |
+
for k in fn_configs.keys():
|
| 91 |
+
fn_configs[k]['df'] = gr.State(df)
|
| 92 |
+
fn_configs[k]['inputs'] = [fn_configs[k]['df']] + fn_configs[k]['inputs']
|
| 93 |
+
|
| 94 |
(
|
| 95 |
player
|
| 96 |
.input(update_dfs, inputs=[player, handedness, source_df], outputs=[app_df, app_league_df, app_pitch_stats, app_league_pitch_stats])
|
|
|
|
| 106 |
# app_df.change(plot_pitch_cards, inputs=[app_df, app_pitch_stats], outputs=pitch_rows+pitch_groups+pitch_names+pitch_infos+pitch_velos+pitch_locs)
|
| 107 |
app_pitch_stats.change(update_velo_stats, inputs=[app_pitch_stats, app_league_pitch_stats], outputs=velo_stats)
|
| 108 |
|
| 109 |
+
# (
|
| 110 |
+
# app_df
|
| 111 |
+
# .change(create_set_download_file_fn('files/player.csv'), inputs=app_df, outputs=download_file)
|
| 112 |
+
# .then(plot_usage, inputs=[app_df, player], outputs=usage)
|
| 113 |
+
# .then(plot_velo_summary, inputs=[app_df, app_league_df, player], outputs=velo_summary)
|
| 114 |
+
# .then(lambda df: plot_loc(df), inputs=app_df, outputs=loc_summary)
|
| 115 |
+
# .then(plot_pitch_cards, inputs=[app_df, app_league_df, app_pitch_stats], outputs=pitch_rows+pitch_groups+pitch_names+pitch_infos+pitch_velos+pitch_locs)
|
| 116 |
+
# )
|
| 117 |
+
|
| 118 |
+
app_df.change(lambda df: copy_dataframe(df, len(fn_configs)), inputs=app_df, outputs=[config['df'] for config in fn_configs.values()])
|
| 119 |
+
|
| 120 |
+
for fn, config in fn_configs.items():
|
| 121 |
+
config['df'].change(fn, inputs=config['inputs'], outputs=config['outputs'])
|
| 122 |
+
|
| 123 |
|
| 124 |
gr.Markdown('## Bugs and other notes')
|
| 125 |
with gr.Accordion('Click to open', open=False):
|