Jimin Park commited on
Commit
3c67330
·
1 Parent(s): 79f2523

added app.py, requirements.txt, and readme.md

Browse files
Files changed (3) hide show
  1. README.md +26 -7
  2. app.py +140 -0
  3. requirements.txt +0 -0
README.md CHANGED
@@ -1,13 +1,32 @@
 
 
1
  ---
2
- title: Lol Champion Pick Predictor
3
- emoji: 🏃
4
- colorFrom: gray
5
- colorTo: pink
6
  sdk: gradio
7
- sdk_version: 5.9.1
8
  app_file: app.py
9
  pinned: false
10
- short_description: Predicts LOL Champion pick
11
  ---
12
 
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # README.md
2
+ """
3
  ---
4
+ title: League of Legends Champion Predictor
5
+ emoji: 🎮
6
+ colorFrom: blue
7
+ colorTo: red
8
  sdk: gradio
9
+ sdk_version: 4.19.2
10
  app_file: app.py
11
  pinned: false
 
12
  ---
13
 
14
+ # League of Legends Champion Prediction
15
+
16
+ This Gradio app predicts the final champion pick in a League of Legends game based on the current team composition.
17
+
18
+ ## Features
19
+ - Player statistics lookup
20
+ - Recent match history display
21
+ - Champion prediction based on current team composition
22
+ - Interactive interface with champion selection dropdowns
23
+
24
+ ## Usage
25
+ 1. Enter player name
26
+ 2. Click "Show Stats" to view player statistics
27
+ 3. Select 9 champions using the dropdowns
28
+ 4. Click "Predict" to get the prediction for the final champion
29
+
30
+ ## Model
31
+ This app uses an XGBoost model trained on League of Legends match data to predict the final champion pick.
32
+ """
app.py ADDED
@@ -0,0 +1,140 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # app.py
2
+ import gradio as gr
3
+ import pandas as pd
4
+ import requests
5
+ import xgboost as xgb
6
+ from huggingface_hub import hf_hub_download
7
+
8
+ # Download the model from Hugging Face Hub
9
+ model_path = hf_hub_download(
10
+ repo_id="YOUR_USERNAME/YOUR_MODEL_REPO", # Replace with your model repo
11
+ filename="model.json" # Replace with your model filename
12
+ )
13
+ model = xgb.Booster()
14
+ model.load_model(model_path)
15
+
16
+ # Rest of your code remains the same as before, but remove demo.launch()
17
+ # Define your interface
18
+ with gr.Blocks() as demo:
19
+ # Assuming you have these helper functions implemented
20
+ def get_player_stats(player_name):
21
+ """Get player statistics from API"""
22
+ # Placeholder - implement actual API call
23
+ return {
24
+ 'wins': 120,
25
+ 'losses': 80,
26
+ 'winrate': '60%',
27
+ 'favorite_champions': ['Ahri', 'Zed', 'Yasuo']
28
+ }
29
+
30
+ def get_recent_matches(player_name):
31
+ """Get recent match history"""
32
+ # Placeholder - implement actual API call
33
+ return pd.DataFrame({
34
+ 'champion': ['Ahri', 'Zed', 'Yasuo'],
35
+ 'result': ['Win', 'Loss', 'Win'],
36
+ 'kda': ['8/2/10', '4/5/3', '12/3/7']
37
+ })
38
+
39
+ def prepare_features(player_name, champions):
40
+ """Prepare features for model prediction"""
41
+ # Placeholder - implement actual feature engineering
42
+ features = [] # Transform champions into model features
43
+ return pd.DataFrame([features])
44
+
45
+ # Load the model from Hugging Face
46
+ model = xgb.Booster() # Initialize model
47
+ # model.load_model("path_to_your_model") # Load your model
48
+
49
+ # Define champion list for dropdowns
50
+ CHAMPIONS = [
51
+ "Aatrox", "Ahri", "Akali", "Alistar", "Amumu",
52
+ # Add more champions...
53
+ ]
54
+
55
+ def show_stats(player_name):
56
+ """Display player statistics and recent matches"""
57
+ if not player_name:
58
+ return "Please enter a player name", None
59
+
60
+ stats = get_player_stats(player_name)
61
+ recent = get_recent_matches(player_name)
62
+
63
+ stats_html = f"""
64
+ <div style='padding: 20px; background: #f5f5f5; border-radius: 10px;'>
65
+ <h3>Player Stats: {player_name}</h3>
66
+ <p>Wins: {stats['wins']} | Losses: {stats['losses']}</p>
67
+ <p>Winrate: {stats['winrate']}</p>
68
+ <p>Favorite Champions: {', '.join(stats['favorite_champions'])}</p>
69
+ </div>
70
+ """
71
+
72
+ return stats_html, recent.to_html(index=False)
73
+
74
+ def predict_champion(player_name, *champions):
75
+ """Make prediction based on selected champions"""
76
+ if not player_name or None in champions:
77
+ return "Please fill in all fields"
78
+
79
+ # Prepare features
80
+ features = prepare_features(player_name, champions)
81
+
82
+ # Make prediction
83
+ prediction = model.predict(features)
84
+
85
+ # Get predicted champion name
86
+ predicted_champion = CHAMPIONS[prediction[0]] # Adjust based on your model output
87
+
88
+ return f"Predicted champion: {predicted_champion}"
89
+
90
+ # Create Gradio interface
91
+ with gr.Blocks() as demo:
92
+ gr.Markdown("# League of Legends Champion Prediction")
93
+
94
+ with gr.Row():
95
+ player_name = gr.Textbox(label="Player Name")
96
+ show_button = gr.Button("Show Stats")
97
+
98
+ with gr.Row():
99
+ stats_output = gr.HTML(label="Player Statistics")
100
+ recent_matches = gr.HTML(label="Recent Matches")
101
+
102
+ with gr.Row():
103
+ champion_dropdowns = [
104
+ gr.Dropdown(choices=CHAMPIONS, label=f"Champion {i+1}")
105
+ for i in range(9)
106
+ ]
107
+
108
+ with gr.Row():
109
+ predict_button = gr.Button("Predict")
110
+ prediction_output = gr.Text(label="Prediction")
111
+
112
+ # Set up event handlers
113
+ show_button.click(
114
+ fn=show_stats,
115
+ inputs=[player_name],
116
+ outputs=[stats_output, recent_matches]
117
+ )
118
+
119
+ predict_button.click(
120
+ fn=predict_champion,
121
+ inputs=[player_name] + champion_dropdowns,
122
+ outputs=prediction_output
123
+ )
124
+
125
+ # Add this line at the end
126
+ demo.queue() # Enable queuing for better handling of multiple users
127
+
128
+
129
+
130
+ # .gitignore
131
+ """
132
+ __pycache__/
133
+ *.py[cod]
134
+ *$py.class
135
+ .env
136
+ .venv
137
+ env/
138
+ venv/
139
+ .DS_Store
140
+ """
requirements.txt ADDED
File without changes