# app.py import gradio as gr import pandas as pd import requests import xgboost as xgb from huggingface_hub import hf_hub_download # Download the model from Hugging Face Hub model_path = hf_hub_download( repo_id="ivwhy/champion-predictor-model", # Replace with your model repo filename="champion_predictor.json" # Replace with your model filename ) model = xgb.Booster() model.load_model(model_path) # Rest of your code remains the same as before, but remove demo.launch() # Define your interface with gr.Blocks() as demo: # Assuming you have these helper functions implemented def get_player_stats(player_name): """Get player statistics from API""" # Placeholder - implement actual API call return { 'wins': 120, 'losses': 80, 'winrate': '60%', 'favorite_champions': ['Ahri', 'Zed', 'Yasuo'] } def get_recent_matches(player_name): """Get recent match history""" # Placeholder - implement actual API call return pd.DataFrame({ 'champion': ['Ahri', 'Zed', 'Yasuo'], 'result': ['Win', 'Loss', 'Win'], 'kda': ['8/2/10', '4/5/3', '12/3/7'] }) def prepare_features(player_name, champions): """Prepare features for model prediction""" # Placeholder - implement actual feature engineering features = [] # Transform champions into model features return pd.DataFrame([features]) # Load the model from Hugging Face model = xgb.Booster() # Initialize model #model.load_model(" ") # Load your model # Define champion list for dropdowns CHAMPIONS = [ "Aatrox", "Ahri", "Akali", "Alistar", "Amumu", # Add more champions... ] def show_stats(player_name): """Display player statistics and recent matches""" if not player_name: return "Please enter a player name", None stats = get_player_stats(player_name) recent = get_recent_matches(player_name) stats_html = f"""

Player Stats: {player_name}

Wins: {stats['wins']} | Losses: {stats['losses']}

Winrate: {stats['winrate']}

Favorite Champions: {', '.join(stats['favorite_champions'])}

""" return stats_html, recent.to_html(index=False) def predict_champion(player_name, *champions): """Make prediction based on selected champions""" if not player_name or None in champions: return "Please fill in all fields" # Prepare features features = prepare_features(player_name, champions) # Make prediction prediction = model.predict(features) # Get predicted champion name predicted_champion = CHAMPIONS[prediction[0]] # Adjust based on your model output return f"Predicted champion: {predicted_champion}" # Create Gradio interface with gr.Blocks() as demo: gr.Markdown("# League of Legends Champion Prediction") with gr.Row(): player_name = gr.Textbox(label="Player Name") show_button = gr.Button("Show Stats") with gr.Row(): stats_output = gr.HTML(label="Player Statistics") recent_matches = gr.HTML(label="Recent Matches") with gr.Row(): champion_dropdowns = [ gr.Dropdown(choices=CHAMPIONS, label=f"Champion {i+1}") for i in range(9) ] with gr.Row(): predict_button = gr.Button("Predict") prediction_output = gr.Text(label="Prediction") # Set up event handlers show_button.click( fn=show_stats, inputs=[player_name], outputs=[stats_output, recent_matches] ) predict_button.click( fn=predict_champion, inputs=[player_name] + champion_dropdowns, outputs=prediction_output ) # Add this line at the end demo.queue() # Enable queuing for better handling of multiple users