Spaces:
Running
Running
File size: 1,361 Bytes
3d0c0d1 |
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 |
import gradio as gr
import polars as pl
from math import ceil
import os
from data import pitch_stats
from gradio_function import *
from css import css
pitch_stats = pitch_stats.rename({'name': 'Player', 'pitch_name': 'Pitch'})
def filter_pitch_leaderboard(min_pitches):
return pitch_stats.filter(pl.col('Count') >= min_pitches).sort('CSW%', descending=True)
def create_pitch_leaderboard():
with gr.Blocks(
css=css
) as pitch_leaderboard_app:
init_min_pitches = 100
pitch_stats.write_csv('pitch_leaderboard.csv')
pitch_leaderboard_df = gr.State(filter_pitch_leaderboard(init_min_pitches))
min_pitches = gr.Number(init_min_pitches, precision=0, label='Min. Pitches')
pitch_leaderboard_download_file = gr.DownloadButton(value='pitch_leaderboard.csv', label='Download leaderboard')
pitch_leaderboard = gr.Dataframe(value=pitch_leaderboard_df.value)
min_pitches.change(filter_pitch_leaderboard, inputs=min_pitches, outputs=pitch_leaderboard_df)
(
pitch_leaderboard_df
.change(create_set_download_file_fn('files/pitch_leaderboard.csv'), inputs=pitch_leaderboard_df, outputs=pitch_leaderboard_download_file)
.then(lambda df: df, inputs=pitch_leaderboard_df, outputs=pitch_leaderboard)
)
return pitch_leaderboard_app
if __name__ == '__main__':
create_pitch_leaderboard().launch(
share=True,
debug=True
) |