Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
adding reload button
Browse files37 unmodified lines3839404142434419 unmodified lines64656667686970717213 unmodified lines8687888990919293945 unmodified lines10010110210310410510610710810911011122 unmodified lines13413513613713813914014114237 unmodified linesresult = meta["model-index"][0]["results"]metrics = result[0]["metrics"]accuracy = metrics[0]["value"]print("ACCURACY", accuracy)return accuracy# We keep the worst case episode19 unmodified linesrow["User"] = user_idrow["Model"] = model_idaccuracy = parse_metrics_accuracy(meta)print("RETURNED ACCURACY", accuracy)mean_reward, std_reward = parse_rewards(accuracy)print("MEAN REWARD", mean_reward)row["Results"] = mean_reward - std_rewardrow["Mean Reward"] = mean_rewardrow["Std Reward"] = std_reward13 unmodified linestable_html = dataframe.to_html(escape=False, index=False)table_html = table_html.replace("<table>", '<table style="width: 100%; margin: auto; border:0.5px solid; border-spacing: 7px 0px">') # center-align the headerstable_html = table_html.replace("<thead>", '<thead align="center">') # center-align the headerstable_html = "<div style='text-align: center ; width:100%'>"+table_html+"</div>"return table_html,dataframe,dataframe.emptyelse:html = """<div style="color: green">5 unmodified linesRL_ENVS = ['LunarLander-v2','CarRacing-v0','MountainCar-v0']RL_DETAILS ={'CarRacing-v0':{'title':" The Car Racing ποΈ Leaderboard π",'data':get_data_per_env('CarRacing-v0')},'MountainCar-v0':{'title':"The Mountain Car β°οΈ π Leaderboard π",'data':get_data_per_env('MountainCar-v0')},'LunarLander-v2':{'title':" The Lunar Lander π Leaderboard π",'data':get_data_per_env('LunarLander-v2')}}block = gr.Blocks()with block:22 unmodified lines# {name_leaderboard}""".format(name_leaderboard = RL_DETAILS[rl_env]['title'])gr.Markdown(markdown)gr.HTML(data_html)block.launch()37 unmodified lines3839404142434419 unmodified lines64656667686970717213 unmodified lines8687888990919293945 unmodified lines10010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314422 unmodified lines16716816917017117217317417517617737 unmodified linesresult = meta["model-index"][0]["results"]metrics = result[0]["metrics"]accuracy = metrics[0]["value"]#print("ACCURACY", accuracy)return accuracy# We keep the worst case episode19 unmodified linesrow["User"] = user_idrow["Model"] = model_idaccuracy = parse_metrics_accuracy(meta)#print("RETURNED ACCURACY", accuracy)mean_reward, std_reward = parse_rewards(accuracy)#print("MEAN REWARD", mean_reward)row["Results"] = mean_reward - std_rewardrow["Mean Reward"] = mean_rewardrow["Std Reward"] = std_reward13 unmodified linestable_html = dataframe.to_html(escape=False, index=False)table_html = table_html.replace("<table>", '<table style="width: 100%; margin: auto; border:0.5px solid; border-spacing: 7px 0px">') # center-align the headerstable_html = table_html.replace("<thead>", '<thead align="left">') # left-align the headerstable_html = "<div style='text-align: left ; width:100%'>"+table_html+"</div>"return table_html,dataframe,dataframe.emptyelse:html = """<div style="color: green">5 unmodified linesRL_ENVS = ['LunarLander-v2','CarRacing-v0','MountainCar-v0']RL_DETAILS ={'CarRacing-v0':{'title':" The Car Racing ποΈ Leaderboard π",'data':get_data_per_env('CarRacing-v0')},'MountainCar-v0':{'title':"The Mountain Car β°οΈ π Leaderboard π",'data':get_data_per_env('MountainCar-v0')},'LunarLander-v2':{'title':" The Lunar Lander π Leaderboard π",'data':get_data_per_env('LunarLander-v2')}}def reload_leaderboard(rl_env):#import pdb;pdb.set_trace()global RL_DETAILSRL_DETAILS[rl_env]['data'] = get_data_per_env(rl_env)data_html,data_dataframe,is_empty = RL_DETAILS[rl_env]['data']if not is_empty:markdown = """# {name_leaderboard}This is a leaderboard of **{len_dataframe}** agents playing {env_name} π©βπ.We use lower bound result to sort the models: mean_reward - std_reward.You can click on the model's name to be redirected to its model card which includes documentation.You want to try your model? Read this [Unit 1](https://github.com/huggingface/deep-rl-class/blob/Unit1/unit1/README.md) of Deep Reinforcement Learning Class.""".format(len_dataframe = len(data_dataframe),env_name = rl_env,name_leaderboard = RL_DETAILS[rl_env]['title'])else:markdown = """# {name_leaderboard}""".format(name_leaderboard = RL_DETAILS[rl_env]['title'])return markdown,data_htmlblock = gr.Blocks()with block:22 unmodified lines# {name_leaderboard}""".format(name_leaderboard = RL_DETAILS[rl_env]['title'])reload = gr.Button('Reload Leaderboard')#env_state = gr.State(rl_env)output_markdown = gr.Markdown(markdown)output_html = gr.HTML(data_html)reload.click(reload_leaderboard,inputs=[rl_env],outputs=[output_markdown,output_html])block.launch()
app.py+43-8