Jimin Park
added app.py, requirements.txt, and readme.md
3c67330
raw
history blame
4 kB
# 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="YOUR_USERNAME/YOUR_MODEL_REPO", # Replace with your model repo
filename="model.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("path_to_your_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"""
<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"
# 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
# .gitignore
"""
__pycache__/
*.py[cod]
*$py.class
.env
.venv
env/
venv/
.DS_Store
"""