Spaces:
Sleeping
Sleeping
| 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 | |
| ) |