|
|
|
import gradio as gr |
|
import pandas as pd |
|
import requests |
|
import xgboost as xgb |
|
from huggingface_hub import hf_hub_download |
|
|
|
|
|
model_path = hf_hub_download( |
|
repo_id="YOUR_USERNAME/YOUR_MODEL_REPO", |
|
filename="model.json" |
|
) |
|
model = xgb.Booster() |
|
model.load_model(model_path) |
|
|
|
|
|
|
|
with gr.Blocks() as demo: |
|
|
|
def get_player_stats(player_name): |
|
"""Get player statistics from API""" |
|
|
|
return { |
|
'wins': 120, |
|
'losses': 80, |
|
'winrate': '60%', |
|
'favorite_champions': ['Ahri', 'Zed', 'Yasuo'] |
|
} |
|
|
|
def get_recent_matches(player_name): |
|
"""Get recent match history""" |
|
|
|
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""" |
|
|
|
features = [] |
|
return pd.DataFrame([features]) |
|
|
|
|
|
model = xgb.Booster() |
|
|
|
|
|
|
|
CHAMPIONS = [ |
|
"Aatrox", "Ahri", "Akali", "Alistar", "Amumu", |
|
|
|
] |
|
|
|
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""" |
|
<div style='padding: 20px; background: #f5f5f5; border-radius: 10px;'> |
|
<h3>Player Stats: {player_name}</h3> |
|
<p>Wins: {stats['wins']} | Losses: {stats['losses']}</p> |
|
<p>Winrate: {stats['winrate']}</p> |
|
<p>Favorite Champions: {', '.join(stats['favorite_champions'])}</p> |
|
</div> |
|
""" |
|
|
|
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" |
|
|
|
|
|
features = prepare_features(player_name, champions) |
|
|
|
|
|
prediction = model.predict(features) |
|
|
|
|
|
predicted_champion = CHAMPIONS[prediction[0]] |
|
|
|
return f"Predicted champion: {predicted_champion}" |
|
|
|
|
|
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") |
|
|
|
|
|
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 |
|
) |
|
|
|
|
|
demo.queue() |
|
|
|
|
|
|
|
|
|
""" |
|
__pycache__/ |
|
*.py[cod] |
|
*$py.class |
|
.env |
|
.venv |
|
env/ |
|
venv/ |
|
.DS_Store |
|
""" |