Spaces:
Runtime error
Runtime error
Commit
β’
e653f9c
1
Parent(s):
659a76d
Add BackgroundScheduler()
Browse files
app.py
CHANGED
@@ -3,10 +3,15 @@ import json
|
|
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 |
|
@@ -75,6 +80,24 @@ rl_envs = [
|
|
75 |
"global": None
|
76 |
},
|
77 |
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
78 |
"rl_env_beautiful": "BipedalWalker-v3",
|
79 |
"rl_env": "BipedalWalker-v3",
|
80 |
"video_link": "",
|
@@ -146,13 +169,13 @@ def get_model_ids(rl_env):
|
|
146 |
api = HfApi()
|
147 |
models = api.list_models(filter=rl_env)
|
148 |
model_ids = [x.modelId for x in models]
|
149 |
-
print(model_ids)
|
150 |
return model_ids
|
151 |
|
152 |
def get_model_dataframe(rl_env):
|
153 |
# Get model ids associated with rl_env
|
154 |
model_ids = get_model_ids(rl_env)
|
155 |
-
print(model_ids)
|
156 |
data = []
|
157 |
for model_id in model_ids:
|
158 |
"""
|
@@ -175,13 +198,14 @@ def get_model_dataframe(rl_env):
|
|
175 |
row["Mean Reward"] = mean_reward
|
176 |
row["Std Reward"] = std_reward
|
177 |
data.append(row)
|
|
|
178 |
ranked_dataframe = rank_dataframe(pd.DataFrame.from_records(data))
|
179 |
print("RANKED", ranked_dataframe)
|
180 |
return ranked_dataframe
|
181 |
|
182 |
|
183 |
def rank_dataframe(dataframe):
|
184 |
-
print("DATAFRAME", dataframe)
|
185 |
dataframe = dataframe.sort_values(by=['Results'], ascending=False)
|
186 |
if not 'Ranking' in dataframe.columns:
|
187 |
dataframe.insert(0, 'Ranking', [i for i in range(1,len(dataframe)+1)])
|
@@ -198,7 +222,7 @@ with block:
|
|
198 |
|
199 |
Just choose which environment you trained your agent on and with Ctrl+F find your rank π
|
200 |
|
201 |
-
**If you don't find your model, go to the bottom of the page and click on the refresh button**
|
202 |
|
203 |
We use **lower bound result to sort the models: mean_reward - std_reward.**
|
204 |
|
@@ -226,10 +250,26 @@ with block:
|
|
226 |
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"])
|
227 |
with gr.Row():
|
228 |
data_run = gr.Button("Refresh")
|
229 |
-
print("rl_env", rl_env["rl_env"])
|
230 |
val = gr.Variable(value=[rl_env["rl_env"]])
|
231 |
data_run.click(get_model_dataframe, inputs=[val], outputs =rl_env["global"])
|
232 |
|
233 |
|
234 |
block.launch()
|
235 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
import requests
|
4 |
|
5 |
from datasets import load_dataset
|
6 |
+
|
7 |
import gradio as gr
|
8 |
+
from apscheduler.schedulers.background import BackgroundScheduler
|
9 |
+
|
10 |
+
|
11 |
from huggingface_hub import HfApi, hf_hub_download
|
12 |
from huggingface_hub.repocard import metadata_load
|
13 |
import pandas as pd
|
14 |
+
|
15 |
from utils import *
|
16 |
|
17 |
|
|
|
80 |
"global": None
|
81 |
},
|
82 |
{
|
83 |
+
"rl_env_beautiful": "PongNoFrameskip-v4 πΎ",
|
84 |
+
"rl_env": "PongNoFrameskip-v4",
|
85 |
+
"video_link": "",
|
86 |
+
"global": None
|
87 |
+
},
|
88 |
+
{
|
89 |
+
"rl_env_beautiful": "BreakoutNoFrameskip-v4 π§±",
|
90 |
+
"rl_env": "BreakoutNoFrameskip-v4",
|
91 |
+
"video_link": "",
|
92 |
+
"global": None
|
93 |
+
},
|
94 |
+
{
|
95 |
+
"rl_env_beautiful": "QbertNoFrameskip-v4 π¦",
|
96 |
+
"rl_env": "QbertNoFrameskip-v4",
|
97 |
+
"video_link": "",
|
98 |
+
"global": None
|
99 |
+
},
|
100 |
+
{
|
101 |
"rl_env_beautiful": "BipedalWalker-v3",
|
102 |
"rl_env": "BipedalWalker-v3",
|
103 |
"video_link": "",
|
|
|
169 |
api = HfApi()
|
170 |
models = api.list_models(filter=rl_env)
|
171 |
model_ids = [x.modelId for x in models]
|
172 |
+
#print(model_ids)
|
173 |
return model_ids
|
174 |
|
175 |
def get_model_dataframe(rl_env):
|
176 |
# Get model ids associated with rl_env
|
177 |
model_ids = get_model_ids(rl_env)
|
178 |
+
#print(model_ids)
|
179 |
data = []
|
180 |
for model_id in model_ids:
|
181 |
"""
|
|
|
198 |
row["Mean Reward"] = mean_reward
|
199 |
row["Std Reward"] = std_reward
|
200 |
data.append(row)
|
201 |
+
print("DATA", data)
|
202 |
ranked_dataframe = rank_dataframe(pd.DataFrame.from_records(data))
|
203 |
print("RANKED", ranked_dataframe)
|
204 |
return ranked_dataframe
|
205 |
|
206 |
|
207 |
def rank_dataframe(dataframe):
|
208 |
+
#print("DATAFRAME", dataframe)
|
209 |
dataframe = dataframe.sort_values(by=['Results'], ascending=False)
|
210 |
if not 'Ranking' in dataframe.columns:
|
211 |
dataframe.insert(0, 'Ranking', [i for i in range(1,len(dataframe)+1)])
|
|
|
222 |
|
223 |
Just choose which environment you trained your agent on and with Ctrl+F find your rank π
|
224 |
|
225 |
+
**The leaderboard is updated every hour. If you don't find your model, go to the bottom of the page and click on the refresh button**
|
226 |
|
227 |
We use **lower bound result to sort the models: mean_reward - std_reward.**
|
228 |
|
|
|
250 |
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"])
|
251 |
with gr.Row():
|
252 |
data_run = gr.Button("Refresh")
|
253 |
+
#print("rl_env", rl_env["rl_env"])
|
254 |
val = gr.Variable(value=[rl_env["rl_env"]])
|
255 |
data_run.click(get_model_dataframe, inputs=[val], outputs =rl_env["global"])
|
256 |
|
257 |
|
258 |
block.launch()
|
259 |
|
260 |
+
def refresh_leaderboard():
|
261 |
+
"""
|
262 |
+
Here we refresh the leaderboard:
|
263 |
+
we update the rl_env["global"] for each rl_envs in rl_env
|
264 |
+
"""
|
265 |
+
for i in range(0, len(rl_envs)):
|
266 |
+
rl_env = rl_envs[i]
|
267 |
+
temp = get_model_dataframe(rl_env)
|
268 |
+
rl_env["global"] = temp
|
269 |
+
print("The leaderboard has been updated")
|
270 |
+
|
271 |
+
scheduler = BackgroundScheduler()
|
272 |
+
# Refresh every hour
|
273 |
+
scheduler.add_job(func=refresh_leaderboard, trigger="interval", seconds=3600)
|
274 |
+
scheduler.start()
|
275 |
+
|