Spaces:
Runtime error
Runtime error
Add base app and comments
Browse files- app.py +45 -0
- matchmaking.py +19 -0
app.py
CHANGED
@@ -11,4 +11,49 @@ from matchmaking import *
|
|
11 |
|
12 |
|
13 |
block = gr.Blocks()
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
|
13 |
block = gr.Blocks()
|
14 |
+
envs = [
|
15 |
+
{
|
16 |
+
"name": "Snowball-Fight",
|
17 |
+
"global": None,
|
18 |
+
},
|
19 |
+
]
|
20 |
|
21 |
+
|
22 |
+
def get_env_data(env_name) -> pd.DataFrame:
|
23 |
+
# data = pd.read_csv(f"env_elos/{env_name}.csv")
|
24 |
+
data = pd.DataFrame(columns=["user", "model", "elo", "games_played"])
|
25 |
+
return data
|
26 |
+
|
27 |
+
|
28 |
+
with block:
|
29 |
+
gr.Markdown(f"""
|
30 |
+
# ๐ The Deep Reinforcement Learning Course Leaderboard ๐
|
31 |
+
|
32 |
+
This is the leaderboard of trained agents during the Deep Reinforcement Learning Course. A free course from beginner to expert.
|
33 |
+
|
34 |
+
Just choose which environment you trained your agent on and with Ctrl+F find your rank ๐
|
35 |
+
|
36 |
+
We use an ELO rating to sort the models.
|
37 |
+
You **can click on the model's name** to be redirected to its model card which includes documentation.
|
38 |
+
|
39 |
+
๐ค You want to try to train your agents? <a href="http://eepurl.com/ic5ZUD" target="_blank">Sign up to the Hugging Face free Deep Reinforcement Learning Course ๐ค </a>.
|
40 |
+
|
41 |
+
You want to compare two agents? <a href="https://huggingface.co/spaces/ThomasSimonini/Compare-Reinforcement-Learning-Agents" target="_blank">It's possible using this Spaces demo ๐ </a>.
|
42 |
+
|
43 |
+
๐ง There is an **environment missing?** Please open an issue.
|
44 |
+
""")
|
45 |
+
|
46 |
+
for i, env in enumerate(envs):
|
47 |
+
with gr.TabItem(env["name"]) as tab:
|
48 |
+
with gr.Row():
|
49 |
+
refresh_data = gr.Button("Refresh")
|
50 |
+
val = gr.Variable(value=[env["name"]])
|
51 |
+
refresh_data.click(get_env_data, inputs=[val], outputs=env["global"])
|
52 |
+
with gr.Row():
|
53 |
+
env["global"] = gr.components.DataFrame(
|
54 |
+
get_env_data(env["name"]),
|
55 |
+
headers=["Ranking ๐", "User ๐ค", "Model id ๐ค", "ELO ๐", "Games played ๐ฎ"],
|
56 |
+
datatype=["number", "markdown", "markdown", "number", "number"]
|
57 |
+
)
|
58 |
+
|
59 |
+
block.launch()
|
matchmaking.py
CHANGED
@@ -4,6 +4,13 @@ import os
|
|
4 |
|
5 |
|
6 |
class Model:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
def __init__(self, name, elo):
|
8 |
self.name = name
|
9 |
self.elo = elo
|
@@ -11,6 +18,15 @@ class Model:
|
|
11 |
|
12 |
|
13 |
class Matchmaking:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
def __init__(self):
|
15 |
self.models = []
|
16 |
self.queue = []
|
@@ -20,6 +36,7 @@ class Matchmaking:
|
|
20 |
self.matches = pd.DataFrame()
|
21 |
|
22 |
def read_history(self):
|
|
|
23 |
path = "match_history"
|
24 |
files = os.listdir(path)
|
25 |
for file in files:
|
@@ -32,6 +49,7 @@ class Matchmaking:
|
|
32 |
self.models = [Model(name, self.start_elo) for name in model_names]
|
33 |
|
34 |
def compute_elo(self):
|
|
|
35 |
for i, row in self.matches.iterrows():
|
36 |
model1 = self.get_model(row["model1"])
|
37 |
model2 = self.get_model(row["model2"])
|
@@ -44,6 +62,7 @@ class Matchmaking:
|
|
44 |
model2.games_played += 1
|
45 |
|
46 |
def get_model(self, name):
|
|
|
47 |
for model in self.models:
|
48 |
if model.name == name:
|
49 |
return model
|
|
|
4 |
|
5 |
|
6 |
class Model:
|
7 |
+
"""
|
8 |
+
Class containing the info of a model.
|
9 |
+
|
10 |
+
:param name: Name of the model
|
11 |
+
:param elo: Elo rating of the model
|
12 |
+
:param games_played: Number of games played by the model (useful if we implement sigma uncertainty)
|
13 |
+
"""
|
14 |
def __init__(self, name, elo):
|
15 |
self.name = name
|
16 |
self.elo = elo
|
|
|
18 |
|
19 |
|
20 |
class Matchmaking:
|
21 |
+
"""
|
22 |
+
Class managing the matchmaking between the models.
|
23 |
+
|
24 |
+
:param models: List of models
|
25 |
+
:param queue: Temporary list of models used for the matching process
|
26 |
+
:param k: Dev coefficient
|
27 |
+
:param max_diff: Maximum difference considered between two models' elo
|
28 |
+
:param matches: Dictionary containing the match history (to later upload as CSV)
|
29 |
+
"""
|
30 |
def __init__(self):
|
31 |
self.models = []
|
32 |
self.queue = []
|
|
|
36 |
self.matches = pd.DataFrame()
|
37 |
|
38 |
def read_history(self):
|
39 |
+
""" Read the match history from the CSV files, concat the Dataframes and sort them by datetime. """
|
40 |
path = "match_history"
|
41 |
files = os.listdir(path)
|
42 |
for file in files:
|
|
|
49 |
self.models = [Model(name, self.start_elo) for name in model_names]
|
50 |
|
51 |
def compute_elo(self):
|
52 |
+
""" Compute the elo for each model after each match. """
|
53 |
for i, row in self.matches.iterrows():
|
54 |
model1 = self.get_model(row["model1"])
|
55 |
model2 = self.get_model(row["model2"])
|
|
|
62 |
model2.games_played += 1
|
63 |
|
64 |
def get_model(self, name):
|
65 |
+
""" Return the Model with the given name. """
|
66 |
for model in self.models:
|
67 |
if model.name == name:
|
68 |
return model
|