CoolFace
Apppublic

jjoseph7/ActualCodingProject

sourceHugging Faceupdated 5mo agoView on Hugging Face
0likes
app.py52 linesDownload Raw Back to root
1 2import pandas as pd3import gradio as gr4 5# Load the dataset (assuming it's in the same directory as app.py on Hugging Face Spaces)6# If running locally without the file, consider adding a try-except or a default DataFrame7df = pd.read_csv('ndwbb_game_history.csv')8 9# Preprocess the data to determine win/loss for Notre Dame10def get_result(row):11    result_str = row['result']12    if result_str.startswith('w') or result_str.startswith('W'):13        return 'Win'14    elif result_str.startswith('l') or result_str.startswith('L'):15        return 'Loss'16    return 'Unknown'17 18df['GameResult'] = df.apply(get_result, axis=1)19 20# Get unique opponent teams21opponent_teams = sorted(df['opponent'].unique().tolist())22 23# Function to calculate win rate24def calculate_win_rate(opponent):25    if opponent not in opponent_teams:26        return f"Opponent '{opponent}' not found in the dataset."27 28    opponent_games = df[df['opponent'] == opponent]29    total_games = len(opponent_games)30 31    if total_games == 0:32        return f"No games found against {opponent}."33 34    wins = opponent_games[opponent_games['GameResult'] == 'Win'].shape[0]35    win_rate = (wins / total_games) * 10036 37    return f"Notre Dame's win rate against {opponent}: {win_rate:.2f}% ( {wins} wins out of {total_games} games)"38 39# Create Gradio interface40iface = gr.Interface(41    fn=calculate_win_rate,42    inputs=gr.Dropdown(choices=opponent_teams, label="Select Opponent Team"),43    outputs="text",44    title="Notre Dame Women's Basketball Win Rate Analyzer",45    description="Select an opponent team to view Notre Dame's historic win rate against them."46)47 48# Launch the Gradio app49# For Hugging Face Spaces, it typically runs automatically, but launch() is good practice50if __name__ == '__main__':51    iface.launch(debug=True)52