Jimin Park commited on
Commit
73e1103
·
1 Parent(s): 3b049ff

readme updated

Browse files
Files changed (1) hide show
  1. app.py +97 -97
app.py CHANGED
@@ -17,110 +17,110 @@ model.load_model(model_path)
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
 
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