Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Commit Β·
e653f9c
1
Parent(s): 659a76d
Add BackgroundScheduler()
Browse files2 unmodified lines345678910111262 unmodified lines75767778798065 unmodified lines14614714814915015115215315415515615715816 unmodified lines17517617717817918018118218318418518618710 unmodified lines19819920020120220320421 unmodified lines2262272282292302312322332342352 unmodified linesimport requestsfrom datasets import load_datasetimport gradio as grfrom huggingface_hub import HfApi, hf_hub_downloadfrom huggingface_hub.repocard import metadata_loadimport pandas as pdfrom utils import *62 unmodified lines"global": None},{"rl_env_beautiful": "BipedalWalker-v3","rl_env": "BipedalWalker-v3","video_link": "",65 unmodified linesapi = HfApi()models = api.list_models(filter=rl_env)model_ids = [x.modelId for x in models]print(model_ids)return model_idsdef get_model_dataframe(rl_env):# Get model ids associated with rl_envmodel_ids = get_model_ids(rl_env)print(model_ids)data = []for model_id in model_ids:"""16 unmodified linesrow["Mean Reward"] = mean_rewardrow["Std Reward"] = std_rewarddata.append(row)ranked_dataframe = rank_dataframe(pd.DataFrame.from_records(data))print("RANKED", ranked_dataframe)return ranked_dataframedef rank_dataframe(dataframe):print("DATAFRAME", dataframe)dataframe = dataframe.sort_values(by=['Results'], ascending=False)if not 'Ranking' in dataframe.columns:dataframe.insert(0, 'Ranking', [i for i in range(1,len(dataframe)+1)])10 unmodified linesJust choose which environment you trained your agent on and with Ctrl+F find your rank π**If you don't find your model, go to the bottom of the page and click on the refresh button**We use **lower bound result to sort the models: mean_reward - std_reward.**21 unmodified linesrl_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"])with gr.Row():data_run = gr.Button("Refresh")print("rl_env", rl_env["rl_env"])val = gr.Variable(value=[rl_env["rl_env"]])data_run.click(get_model_dataframe, inputs=[val], outputs =rl_env["global"])block.launch()2 unmodified lines3456789101112131415161762 unmodified lines808182838485868788899091929394959697989910010110210365 unmodified lines16917017117217317417517617717817918018116 unmodified lines19819920020120220320420520620720820921021110 unmodified lines22222322422522622722821 unmodified lines2502512522532542552562572582592602612622632642652662672682692702712722732742752 unmodified linesimport requestsfrom datasets import load_datasetimport gradio as grfrom apscheduler.schedulers.background import BackgroundSchedulerfrom huggingface_hub import HfApi, hf_hub_downloadfrom huggingface_hub.repocard import metadata_loadimport pandas as pdfrom utils import *62 unmodified lines"global": None},{"rl_env_beautiful": "PongNoFrameskip-v4 πΎ","rl_env": "PongNoFrameskip-v4","video_link": "","global": None},{"rl_env_beautiful": "BreakoutNoFrameskip-v4 π§±","rl_env": "BreakoutNoFrameskip-v4","video_link": "","global": None},{"rl_env_beautiful": "QbertNoFrameskip-v4 π¦","rl_env": "QbertNoFrameskip-v4","video_link": "","global": None},{"rl_env_beautiful": "BipedalWalker-v3","rl_env": "BipedalWalker-v3","video_link": "",65 unmodified linesapi = HfApi()models = api.list_models(filter=rl_env)model_ids = [x.modelId for x in models]#print(model_ids)return model_idsdef get_model_dataframe(rl_env):# Get model ids associated with rl_envmodel_ids = get_model_ids(rl_env)#print(model_ids)data = []for model_id in model_ids:"""16 unmodified linesrow["Mean Reward"] = mean_rewardrow["Std Reward"] = std_rewarddata.append(row)print("DATA", data)ranked_dataframe = rank_dataframe(pd.DataFrame.from_records(data))print("RANKED", ranked_dataframe)return ranked_dataframedef rank_dataframe(dataframe):#print("DATAFRAME", dataframe)dataframe = dataframe.sort_values(by=['Results'], ascending=False)if not 'Ranking' in dataframe.columns:dataframe.insert(0, 'Ranking', [i for i in range(1,len(dataframe)+1)])10 unmodified linesJust choose which environment you trained your agent on and with Ctrl+F find your rank π**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**We use **lower bound result to sort the models: mean_reward - std_reward.**21 unmodified linesrl_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"])with gr.Row():data_run = gr.Button("Refresh")#print("rl_env", rl_env["rl_env"])val = gr.Variable(value=[rl_env["rl_env"]])data_run.click(get_model_dataframe, inputs=[val], outputs =rl_env["global"])block.launch()def refresh_leaderboard():"""Here we refresh the leaderboard:we update the rl_env["global"] for each rl_envs in rl_env"""for i in range(0, len(rl_envs)):rl_env = rl_envs[i]temp = get_model_dataframe(rl_env)rl_env["global"] = tempprint("The leaderboard has been updated")scheduler = BackgroundScheduler()# Refresh every hourscheduler.add_job(func=refresh_leaderboard, trigger="interval", seconds=3600)scheduler.start()
app.py+45-5