Big Leaderboard Update
Browse files
README.md
CHANGED
@@ -4,7 +4,7 @@ emoji: π
|
|
4 |
colorFrom: green
|
5 |
colorTo: indigo
|
6 |
sdk: gradio
|
7 |
-
sdk_version: 3.0
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
---
|
|
|
4 |
colorFrom: green
|
5 |
colorTo: indigo
|
6 |
sdk: gradio
|
7 |
+
sdk_version: 3.11.0
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
---
|
app.css
DELETED
@@ -1,37 +0,0 @@
|
|
1 |
-
|
2 |
-
.infoPoint h1 {
|
3 |
-
font-size: 30px;
|
4 |
-
text-decoration: bold;
|
5 |
-
|
6 |
-
}
|
7 |
-
|
8 |
-
a {
|
9 |
-
text-decoration: underline;
|
10 |
-
color: #1f3b54 ;
|
11 |
-
}
|
12 |
-
|
13 |
-
table {
|
14 |
-
|
15 |
-
margin: 25px 0;
|
16 |
-
font-size: 0.9em;
|
17 |
-
font-family: sans-serif;
|
18 |
-
min-width: 400px;
|
19 |
-
box-shadow: 0 0 20px rgba(0, 0, 0, 0.15);
|
20 |
-
}
|
21 |
-
|
22 |
-
table th,
|
23 |
-
table td {
|
24 |
-
padding: 12px 15px;
|
25 |
-
}
|
26 |
-
|
27 |
-
tr {
|
28 |
-
text-align: left;
|
29 |
-
}
|
30 |
-
thead tr {
|
31 |
-
text-align: left;
|
32 |
-
}
|
33 |
-
|
34 |
-
.flex
|
35 |
-
{
|
36 |
-
overflow:auto;
|
37 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.py
CHANGED
@@ -1,238 +1,225 @@
|
|
|
|
|
|
1 |
import requests
|
2 |
-
import pandas as pd
|
3 |
-
from tqdm.auto import tqdm
|
4 |
-
from utils import *
|
5 |
-
import gradio as gr
|
6 |
|
|
|
|
|
7 |
from huggingface_hub import HfApi, hf_hub_download
|
8 |
from huggingface_hub.repocard import metadata_load
|
|
|
|
|
9 |
|
10 |
-
class DeepRL_Leaderboard:
|
11 |
-
def __init__(self) -> None:
|
12 |
-
self.leaderboard= {}
|
13 |
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
-
|
24 |
-
|
|
|
|
|
25 |
|
26 |
-
# CSS file for the
|
27 |
-
with open('app.css','r') as f:
|
28 |
-
BLOCK_CSS = f.read()
|
29 |
|
30 |
-
|
31 |
-
|
|
|
|
|
|
|
|
|
32 |
|
33 |
-
def
|
34 |
-
|
35 |
-
data = []
|
36 |
model_ids = get_model_ids(rl_env)
|
37 |
-
LOADED_MODEL_IDS[rl_env]=model_ids
|
38 |
-
|
39 |
-
for model_id in tqdm(model_ids):
|
40 |
-
meta = get_metadata(model_id)
|
41 |
-
LOADED_MODEL_METADATA[model_id] = meta if meta is not None else ''
|
42 |
-
if meta is None:
|
43 |
-
continue
|
44 |
-
user_id = model_id.split('/')[0]
|
45 |
-
row = {}
|
46 |
-
row["User"] = user_id
|
47 |
-
row["Model"] = model_id
|
48 |
-
accuracy = parse_metrics_accuracy(meta)
|
49 |
-
mean_reward, std_reward = parse_rewards(accuracy)
|
50 |
-
mean_reward = mean_reward if not pd.isna(mean_reward) else 0
|
51 |
-
std_reward = std_reward if not pd.isna(std_reward) else 0
|
52 |
-
row["Results"] = mean_reward - std_reward
|
53 |
-
row["Mean Reward"] = mean_reward
|
54 |
-
row["Std Reward"] = std_reward
|
55 |
-
data.append(row)
|
56 |
-
return pd.DataFrame.from_records(data)
|
57 |
-
|
58 |
-
def get_data_per_env(rl_env):
|
59 |
-
dataframe = get_data(rl_env)
|
60 |
-
dataframe = dataframe.fillna("")
|
61 |
-
|
62 |
-
if not dataframe.empty:
|
63 |
-
# turn the model ids into clickable links
|
64 |
-
dataframe["User"] = dataframe["User"].apply(make_clickable_user)
|
65 |
-
dataframe["Model"] = dataframe["Model"].apply(make_clickable_model)
|
66 |
-
dataframe = dataframe.sort_values(by=['Results'], ascending=False)
|
67 |
-
if not 'Ranking' in dataframe.columns:
|
68 |
-
dataframe.insert(0, 'Ranking', [i for i in range(1,len(dataframe)+1)])
|
69 |
-
else:
|
70 |
-
dataframe['Ranking'] = [i for i in range(1,len(dataframe)+1)]
|
71 |
-
table_html = dataframe.to_html(escape=False, index=False,justify = 'left')
|
72 |
-
return table_html,dataframe,dataframe.empty
|
73 |
-
else:
|
74 |
-
html = """<div style="color: green">
|
75 |
-
<p> β Please wait. Results will be out soon... </p>
|
76 |
-
</div>
|
77 |
-
"""
|
78 |
-
return html,dataframe,dataframe.empty
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
rl_leaderboard = DeepRL_Leaderboard()
|
83 |
-
rl_leaderboard.add_leaderboard('CartPole-v1','The Cartpole-v1 Leaderboard')
|
84 |
-
rl_leaderboard.add_leaderboard('LunarLander-v2',"The Lunar Lander π Leaderboard")
|
85 |
-
rl_leaderboard.add_leaderboard('FrozenLake-v1-4x4-no_slippery','The FrozenLake-v1-4x4-no_slippery Leaderboard')
|
86 |
-
rl_leaderboard.add_leaderboard('FrozenLake-v1-8x8-no_slippery','The FrozenLake-v1-8x8-no_slippery Leaderboard')
|
87 |
-
rl_leaderboard.add_leaderboard('FrozenLake-v1-4x4','The FrozenLake-v1-4x4 Leaderboard')
|
88 |
-
rl_leaderboard.add_leaderboard('FrozenLake-v1-8x8','The FrozenLake-v1-8x8 Leaderboard')
|
89 |
-
rl_leaderboard.add_leaderboard('Taxi-v3','The Taxi-v3π Leaderboard')
|
90 |
-
rl_leaderboard.add_leaderboard('CarRacing-v0'," The Car Racing ποΈ Leaderboard")
|
91 |
-
rl_leaderboard.add_leaderboard('MountainCar-v0',"The Mountain Car β°οΈ π Leaderboard")
|
92 |
-
rl_leaderboard.add_leaderboard('BipedalWalker-v3',"The BipedalWalker Leaderboard")
|
93 |
-
rl_leaderboard.add_leaderboard('SpaceInvadersNoFrameskip-v4','The SpaceInvadersNoFrameskip-v4 Leaderboard')
|
94 |
-
rl_leaderboard.add_leaderboard('Pixelcopter-PLE-v0','The Pixelcopter-PLE-v0 π Leaderboard')
|
95 |
-
rl_leaderboard.add_leaderboard('Pong-PLE-v0','The Pong-PLE-v0 πΎ Leaderboard')
|
96 |
-
rl_leaderboard.add_leaderboard('Walker2DBulletEnv-v0','The Walker2DBulletEnv-v0 π€ Leaderboard')
|
97 |
-
rl_leaderboard.add_leaderboard('AntBulletEnv-v0','The AntBulletEnv-v0 πΈοΈ Leaderboard')
|
98 |
-
rl_leaderboard.add_leaderboard('HalfCheetahBulletEnv-v0','The HalfCheetahBulletEnv-v0 π€ Leaderboard')
|
99 |
-
RL_ENVS = rl_leaderboard.get_ids()
|
100 |
-
RL_DETAILS = rl_leaderboard.get_data()
|
101 |
-
|
102 |
-
|
103 |
-
def update_data(rl_env):
|
104 |
-
global LOADED_MODEL_IDS,LOADED_MODEL_METADATA
|
105 |
data = []
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
meta = get_metadata(model_id)
|
112 |
-
LOADED_MODEL_METADATA[model_id] = meta if meta is not None else ''
|
113 |
if meta is None:
|
114 |
continue
|
115 |
user_id = model_id.split('/')[0]
|
116 |
row = {}
|
117 |
-
row["User"] = user_id
|
118 |
-
row["Model"] = model_id
|
119 |
accuracy = parse_metrics_accuracy(meta)
|
120 |
mean_reward, std_reward = parse_rewards(accuracy)
|
121 |
mean_reward = mean_reward if not pd.isna(mean_reward) else 0
|
122 |
std_reward = std_reward if not pd.isna(std_reward) else 0
|
123 |
-
|
124 |
row["Results"] = mean_reward - std_reward
|
125 |
row["Mean Reward"] = mean_reward
|
126 |
row["Std Reward"] = std_reward
|
127 |
data.append(row)
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
def update_data_per_env(rl_env):
|
132 |
-
global RL_DETAILS
|
133 |
-
|
134 |
-
_,old_dataframe,_ = RL_DETAILS[rl_env]['data']
|
135 |
-
new_dataframe = update_data(rl_env)
|
136 |
-
|
137 |
-
new_dataframe = new_dataframe.fillna("")
|
138 |
-
if not new_dataframe.empty:
|
139 |
-
new_dataframe["User"] = new_dataframe["User"].apply(make_clickable_user)
|
140 |
-
new_dataframe["Model"] = new_dataframe["Model"].apply(make_clickable_model)
|
141 |
-
|
142 |
-
dataframe = pd.concat([old_dataframe,new_dataframe])
|
143 |
-
|
144 |
-
if not dataframe.empty:
|
145 |
-
|
146 |
-
dataframe = dataframe.sort_values(by=['Results'], ascending=False)
|
147 |
-
if not 'Ranking' in dataframe.columns:
|
148 |
-
dataframe.insert(0, 'Ranking', [i for i in range(1,len(dataframe)+1)])
|
149 |
-
else:
|
150 |
-
dataframe['Ranking'] = [i for i in range(1,len(dataframe)+1)]
|
151 |
-
table_html = dataframe.to_html(escape=False, index=False,justify = 'left')
|
152 |
-
return table_html,dataframe,dataframe.empty
|
153 |
-
else:
|
154 |
-
html = """<div style="color: green">
|
155 |
-
<p> β Please wait. Results will be out soon... </p>
|
156 |
-
</div>
|
157 |
-
"""
|
158 |
-
return html,dataframe,dataframe.empty
|
159 |
-
|
160 |
-
|
161 |
-
def get_info_display(dataframe,env_name,name_leaderboard,is_empty):
|
162 |
-
if not is_empty:
|
163 |
-
markdown = """
|
164 |
-
<div class='infoPoint'>
|
165 |
-
<h1> {name_leaderboard} </h1>
|
166 |
-
<br>
|
167 |
-
<p> This is a leaderboard of <b>{len_dataframe}</b> agents, from <b>{num_unique_users}</b> unique users, playing {env_name} π©βπ. </p>
|
168 |
-
<br>
|
169 |
-
<p> We use <b>lower bound result to sort the models: mean_reward - std_reward.</b> </p>
|
170 |
-
<br>
|
171 |
-
<p> You can click on the model's name to be redirected to its model card which includes documentation. </p>
|
172 |
-
<br>
|
173 |
-
<p> You want to try to train your agents? <a href="http://eepurl.com/h1pElX" target="_blank">Sign up to the Hugging Face free Deep Reinforcement Learning Class π€ </a>.
|
174 |
-
</p>
|
175 |
-
<br>
|
176 |
-
<p> 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>.
|
177 |
-
</p>
|
178 |
-
</div>
|
179 |
-
""".format(len_dataframe = len(dataframe),env_name = env_name,name_leaderboard = name_leaderboard,num_unique_users = len(set(dataframe['User'].values)))
|
180 |
-
|
181 |
-
else:
|
182 |
-
markdown = """
|
183 |
-
<div class='infoPoint'>
|
184 |
-
<h1> {name_leaderboard} </h1>
|
185 |
-
<br>
|
186 |
-
</div>
|
187 |
-
""".format(name_leaderboard = name_leaderboard)
|
188 |
-
return markdown
|
189 |
-
|
190 |
-
def reload_all_data():
|
191 |
-
|
192 |
-
global RL_DETAILS,RL_ENVS
|
193 |
-
|
194 |
-
for rl_env in RL_ENVS:
|
195 |
-
RL_DETAILS[rl_env]['data'] = update_data_per_env(rl_env)
|
196 |
-
|
197 |
-
html = """<div style="color: green">
|
198 |
-
<p> β
Leaderboard updated! </p>
|
199 |
-
</div>
|
200 |
-
"""
|
201 |
-
return html
|
202 |
-
|
203 |
-
|
204 |
-
def reload_leaderboard(rl_env):
|
205 |
-
global RL_DETAILS
|
206 |
-
|
207 |
-
data_html,data_dataframe,is_empty = RL_DETAILS[rl_env]['data']
|
208 |
-
|
209 |
-
markdown = get_info_display(data_dataframe,rl_env,RL_DETAILS[rl_env]['title'],is_empty)
|
210 |
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
|
|
|
|
|
|
|
|
216 |
|
217 |
|
218 |
-
block = gr.Blocks(css=BLOCK_CSS)
|
219 |
with block:
|
220 |
-
|
221 |
-
|
222 |
-
</div>
|
223 |
-
""")
|
224 |
-
block.load(reload_all_data,[],[notification])
|
225 |
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
env_state =gr.Variable(value=f'\"{rl_env}\"')
|
232 |
-
output_markdown = gr.HTML(markdown)
|
233 |
-
|
234 |
-
output_html = gr.HTML(data_html)
|
235 |
|
236 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
237 |
|
238 |
-
block.launch()
|
|
|
1 |
+
import json
|
2 |
+
|
3 |
import requests
|
|
|
|
|
|
|
|
|
4 |
|
5 |
+
from datasets import load_dataset
|
6 |
+
import gradio as gr
|
7 |
from huggingface_hub import HfApi, hf_hub_download
|
8 |
from huggingface_hub.repocard import metadata_load
|
9 |
+
import pandas as pd
|
10 |
+
from utils import *
|
11 |
|
|
|
|
|
|
|
12 |
|
13 |
+
block = gr.Blocks()
|
14 |
+
|
15 |
+
# Containing the data
|
16 |
+
rl_envs = [{
|
17 |
+
"rl_env_beautiful": "CartPole-v1",
|
18 |
+
"rl_env": "CartPole-v1",
|
19 |
+
"video_link": "https://huggingface.co/sb3/ppo-CartPole-v1/resolve/main/replay.mp4",
|
20 |
+
"global": None
|
21 |
+
},
|
22 |
+
{
|
23 |
+
"rl_env_beautiful": "FrozenLake-v1-4x4-no_slippery βοΈ",
|
24 |
+
"rl_env": "FrozenLake-v1-4x4-no_slippery",
|
25 |
+
"video_link": "",
|
26 |
+
"global": None
|
27 |
+
},
|
28 |
+
{
|
29 |
+
"rl_env_beautiful": "FrozenLake-v1-8x8-no_slippery βοΈ",
|
30 |
+
"rl_env": "FrozenLake-v1-8x8-no_slippery",
|
31 |
+
"video_link": "",
|
32 |
+
"global": None
|
33 |
+
},
|
34 |
+
{
|
35 |
+
"rl_env_beautiful": "FrozenLake-v1-4x4 βοΈ",
|
36 |
+
"rl_env": "FrozenLake-v1-4x4",
|
37 |
+
"video_link": "",
|
38 |
+
"global": None
|
39 |
+
},
|
40 |
+
{
|
41 |
+
"rl_env_beautiful": "FrozenLake-v1-8x8 βοΈ",
|
42 |
+
"rl_env": "FrozenLake-v1-8x8",
|
43 |
+
"video_link": "",
|
44 |
+
"global": None
|
45 |
+
},
|
46 |
+
{
|
47 |
+
"rl_env_beautiful": "Taxi-v3 π",
|
48 |
+
"rl_env": "Taxi-v3",
|
49 |
+
"video_link": "",
|
50 |
+
"global": None
|
51 |
+
},
|
52 |
+
{
|
53 |
+
"rl_env_beautiful": "CarRacing-v0 ποΈ",
|
54 |
+
"rl_env": "CarRacing-v0",
|
55 |
+
"video_link": "",
|
56 |
+
"global": None
|
57 |
+
},
|
58 |
+
{
|
59 |
+
"rl_env_beautiful": "MountainCar-v0 β°οΈ",
|
60 |
+
"rl_env": "MountainCar-v0",
|
61 |
+
"video_link": "",
|
62 |
+
"global": None
|
63 |
+
},
|
64 |
+
{
|
65 |
+
"rl_env_beautiful": "SpaceInvadersNoFrameskip-v4 πΎ",
|
66 |
+
"rl_env": "SpaceInvadersNoFrameskip-v4",
|
67 |
+
"video_link": "",
|
68 |
+
"global": None
|
69 |
+
},
|
70 |
+
{
|
71 |
+
"rl_env_beautiful": "BipedalWalker-v3",
|
72 |
+
"rl_env": "BipedalWalker-v3",
|
73 |
+
"video_link": "",
|
74 |
+
"global": None
|
75 |
+
},
|
76 |
+
{
|
77 |
+
"rl_env_beautiful": "Walker2DBulletEnv-v0",
|
78 |
+
"rl_env": "Walker2DBulletEnv-v0",
|
79 |
+
"video_link": "",
|
80 |
+
"global": None
|
81 |
+
},
|
82 |
+
{
|
83 |
+
"rl_env_beautiful": "AntBulletEnv-v0",
|
84 |
+
"rl_env": "AntBulletEnv-v0",
|
85 |
+
"video_link": "",
|
86 |
+
"global": None
|
87 |
+
},
|
88 |
+
{
|
89 |
+
"rl_env_beautiful": "HalfCheetahBulletEnv-v0",
|
90 |
+
"rl_env": "HalfCheetahBulletEnv-v0",
|
91 |
+
"video_link": "",
|
92 |
+
"global": None
|
93 |
+
}
|
94 |
+
]
|
95 |
+
|
96 |
+
|
97 |
+
|
98 |
+
def get_metadata(model_id):
|
99 |
+
try:
|
100 |
+
readme_path = hf_hub_download(model_id, filename="README.md")
|
101 |
+
return metadata_load(readme_path)
|
102 |
+
except requests.exceptions.HTTPError:
|
103 |
+
# 404 README.md not found
|
104 |
+
return None
|
105 |
+
|
106 |
+
def parse_metrics_accuracy(meta):
|
107 |
+
if "model-index" not in meta:
|
108 |
+
return None
|
109 |
+
result = meta["model-index"][0]["results"]
|
110 |
+
metrics = result[0]["metrics"]
|
111 |
+
accuracy = metrics[0]["value"]
|
112 |
+
return accuracy
|
113 |
+
|
114 |
+
# We keep the worst case episode
|
115 |
+
def parse_rewards(accuracy):
|
116 |
+
default_std = -1000
|
117 |
+
default_reward=-1000
|
118 |
+
if accuracy != None:
|
119 |
+
accuracy = str(accuracy)
|
120 |
+
parsed = accuracy.split(' +/- ')
|
121 |
+
if len(parsed)>1:
|
122 |
+
mean_reward = float(parsed[0])
|
123 |
+
std_reward = float(parsed[1])
|
124 |
+
elif len(parsed)==1: #only mean reward
|
125 |
+
mean_reward = float(parsed[0])
|
126 |
+
std_reward = float(0)
|
127 |
+
|
128 |
+
else:
|
129 |
+
mean_reward = float(default_std)
|
130 |
+
std_reward = float(default_reward)
|
131 |
|
132 |
+
else:
|
133 |
+
mean_reward = float(default_std)
|
134 |
+
std_reward = float(default_reward)
|
135 |
+
return mean_reward, std_reward
|
136 |
|
|
|
|
|
|
|
137 |
|
138 |
+
def get_model_ids(rl_env):
|
139 |
+
api = HfApi()
|
140 |
+
models = api.list_models(filter=rl_env)
|
141 |
+
model_ids = [x.modelId for x in models]
|
142 |
+
print(model_ids)
|
143 |
+
return model_ids
|
144 |
|
145 |
+
def get_model_dataframe(rl_env):
|
146 |
+
# Get model ids associated with rl_env
|
|
|
147 |
model_ids = get_model_ids(rl_env)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
148 |
data = []
|
149 |
+
for model_id in model_ids:
|
150 |
+
"""
|
151 |
+
readme_path = hf_hub_download(model_id, filename="README.md")
|
152 |
+
meta = metadata_load(readme_path)
|
153 |
+
"""
|
154 |
meta = get_metadata(model_id)
|
155 |
+
#LOADED_MODEL_METADATA[model_id] = meta if meta is not None else ''
|
156 |
if meta is None:
|
157 |
continue
|
158 |
user_id = model_id.split('/')[0]
|
159 |
row = {}
|
160 |
+
row["User"] = make_clickable_user(user_id)
|
161 |
+
row["Model"] = make_clickable_model(model_id)
|
162 |
accuracy = parse_metrics_accuracy(meta)
|
163 |
mean_reward, std_reward = parse_rewards(accuracy)
|
164 |
mean_reward = mean_reward if not pd.isna(mean_reward) else 0
|
165 |
std_reward = std_reward if not pd.isna(std_reward) else 0
|
|
|
166 |
row["Results"] = mean_reward - std_reward
|
167 |
row["Mean Reward"] = mean_reward
|
168 |
row["Std Reward"] = std_reward
|
169 |
data.append(row)
|
170 |
+
ranked_dataframe = rank_dataframe(pd.DataFrame.from_records(data))
|
171 |
+
print("RANKED", ranked_dataframe)
|
172 |
+
return ranked_dataframe
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
173 |
|
174 |
+
|
175 |
+
def rank_dataframe(dataframe):
|
176 |
+
print("DATAFRAME", dataframe)
|
177 |
+
dataframe = dataframe.sort_values(by=['Results'], ascending=False)
|
178 |
+
if not 'Ranking' in dataframe.columns:
|
179 |
+
dataframe.insert(0, 'Ranking', [i for i in range(1,len(dataframe)+1)])
|
180 |
+
else:
|
181 |
+
dataframe['Ranking'] = [i for i in range(1,len(dataframe)+1)]
|
182 |
+
return dataframe
|
183 |
|
184 |
|
|
|
185 |
with block:
|
186 |
+
gr.Markdown(f"""
|
187 |
+
# π The Deep Reinforcement Learning Course Leaderboard π
|
|
|
|
|
|
|
188 |
|
189 |
+
This is the leaderboard of trained agents during the Deep Reinforcement Learning Course. A free course from beginner to expert.
|
190 |
+
|
191 |
+
Just choose which environment you trained your agent on and with Ctrl+F find your rank π
|
192 |
+
|
193 |
+
We use **lower bound result to sort the models: mean_reward - std_reward.**
|
|
|
|
|
|
|
|
|
194 |
|
195 |
+
You **can click on the model's name** to be redirected to its model card which includes documentation.
|
196 |
+
|
197 |
+
π€ 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>.
|
198 |
+
|
199 |
+
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>.
|
200 |
+
|
201 |
+
π§ There is an **environment missing?** Please open an issue.
|
202 |
+
""")
|
203 |
+
|
204 |
+
#for rl_env in RL_ENVS:
|
205 |
+
for i in range(0, len(rl_envs)):
|
206 |
+
rl_env = rl_envs[i]
|
207 |
+
|
208 |
+
with gr.TabItem(rl_env["rl_env_beautiful"]) as rl_tab:
|
209 |
+
with gr.Row():
|
210 |
+
markdown = """
|
211 |
+
# {name_leaderboard}
|
212 |
+
|
213 |
+
""".format(name_leaderboard = rl_env["rl_env_beautiful"], video_link = rl_env["video_link"])
|
214 |
+
gr.Markdown(markdown)
|
215 |
+
with gr.Row():
|
216 |
+
rl_env["global"] = gr.components.Dataframe(value= get_model_dataframe(rl_env["rl_env"]), headers=["Ranking π", "User π€", "Model id π€", "Results", "Mean Reward", "Std Reward"], datatype=["number", "markdown", "markdown", "number", "number", "number"])
|
217 |
+
with gr.Row():
|
218 |
+
data_run = gr.Button("Refresh")
|
219 |
+
print("rl_env", rl_env["rl_env"])
|
220 |
+
val = gr.Variable(value=[rl_env["rl_env"]])
|
221 |
+
data_run.click(get_model_dataframe, inputs=[val], outputs =rl_env["global"])
|
222 |
+
|
223 |
+
|
224 |
+
block.launch()
|
225 |
|
|
utils.py
CHANGED
@@ -1,10 +1,3 @@
|
|
1 |
-
import pandas as pd
|
2 |
-
import requests
|
3 |
-
from tqdm.auto import tqdm
|
4 |
-
from huggingface_hub import HfApi, hf_hub_download
|
5 |
-
from huggingface_hub.repocard import metadata_load
|
6 |
-
|
7 |
-
|
8 |
# Based on Omar Sanseviero work
|
9 |
# Make model clickable link
|
10 |
def make_clickable_model(model_name):
|
@@ -18,51 +11,4 @@ def make_clickable_model(model_name):
|
|
18 |
def make_clickable_user(user_id):
|
19 |
link = "https://huggingface.co/" + user_id
|
20 |
return f'<a target="_blank" href="{link}">{user_id}</a>'
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
def get_model_ids(rl_env):
|
25 |
-
api = HfApi()
|
26 |
-
models = api.list_models(filter=rl_env)
|
27 |
-
model_ids = [x.modelId for x in models]
|
28 |
-
return model_ids
|
29 |
-
|
30 |
-
def get_metadata(model_id):
|
31 |
-
try:
|
32 |
-
readme_path = hf_hub_download(model_id, filename="README.md")
|
33 |
-
return metadata_load(readme_path)
|
34 |
-
except requests.exceptions.HTTPError:
|
35 |
-
# 404 README.md not found
|
36 |
-
return None
|
37 |
-
|
38 |
-
def parse_metrics_accuracy(meta):
|
39 |
-
if "model-index" not in meta:
|
40 |
-
return None
|
41 |
-
result = meta["model-index"][0]["results"]
|
42 |
-
metrics = result[0]["metrics"]
|
43 |
-
accuracy = metrics[0]["value"]
|
44 |
-
return accuracy
|
45 |
-
|
46 |
-
# We keep the worst case episode
|
47 |
-
def parse_rewards(accuracy):
|
48 |
-
default_std = -1000
|
49 |
-
default_reward=-1000
|
50 |
-
if accuracy != None:
|
51 |
-
accuracy = str(accuracy)
|
52 |
-
parsed = accuracy.split(' +/- ')
|
53 |
-
if len(parsed)>1:
|
54 |
-
mean_reward = float(parsed[0])
|
55 |
-
std_reward = float(parsed[1])
|
56 |
-
elif len(parsed)==1: #only mean reward
|
57 |
-
mean_reward = float(parsed[0])
|
58 |
-
std_reward = float(0)
|
59 |
-
|
60 |
-
else:
|
61 |
-
mean_reward = float(default_std)
|
62 |
-
std_reward = float(default_reward)
|
63 |
-
|
64 |
-
else:
|
65 |
-
mean_reward = float(default_std)
|
66 |
-
std_reward = float(default_reward)
|
67 |
-
return mean_reward, std_reward
|
68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
# Based on Omar Sanseviero work
|
2 |
# Make model clickable link
|
3 |
def make_clickable_model(model_name):
|
|
|
11 |
def make_clickable_user(user_id):
|
12 |
link = "https://huggingface.co/" + user_id
|
13 |
return f'<a target="_blank" href="{link}">{user_id}</a>'
|
14 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|