Spaces:
Runtime error
Runtime error
adding reload button
Browse files
app.py
CHANGED
@@ -38,7 +38,7 @@ def parse_metrics_accuracy(meta):
|
|
38 |
result = meta["model-index"][0]["results"]
|
39 |
metrics = result[0]["metrics"]
|
40 |
accuracy = metrics[0]["value"]
|
41 |
-
print("ACCURACY", accuracy)
|
42 |
return accuracy
|
43 |
|
44 |
# We keep the worst case episode
|
@@ -64,9 +64,9 @@ def get_data(rl_env):
|
|
64 |
row["User"] = user_id
|
65 |
row["Model"] = model_id
|
66 |
accuracy = parse_metrics_accuracy(meta)
|
67 |
-
print("RETURNED ACCURACY", accuracy)
|
68 |
mean_reward, std_reward = parse_rewards(accuracy)
|
69 |
-
print("MEAN REWARD", mean_reward)
|
70 |
row["Results"] = mean_reward - std_reward
|
71 |
row["Mean Reward"] = mean_reward
|
72 |
row["Std Reward"] = std_reward
|
@@ -86,9 +86,9 @@ def get_data_per_env(rl_env):
|
|
86 |
table_html = dataframe.to_html(escape=False, index=False)
|
87 |
table_html = table_html.replace("<table>", '<table style="width: 100%; margin: auto; border:0.5px solid; border-spacing: 7px 0px">') # center-align the headers
|
88 |
|
89 |
-
table_html = table_html.replace("<thead>", '<thead align="
|
90 |
|
91 |
-
table_html = "<div style='text-align:
|
92 |
return table_html,dataframe,dataframe.empty
|
93 |
else:
|
94 |
html = """<div style="color: green">
|
@@ -100,12 +100,45 @@ def get_data_per_env(rl_env):
|
|
100 |
|
101 |
|
102 |
RL_ENVS = ['LunarLander-v2','CarRacing-v0','MountainCar-v0']
|
|
|
103 |
RL_DETAILS ={'CarRacing-v0':{'title':" The Car Racing ποΈ Leaderboard π",'data':get_data_per_env('CarRacing-v0')},
|
104 |
'MountainCar-v0':{'title':"The Mountain Car β°οΈ π Leaderboard π",'data':get_data_per_env('MountainCar-v0')},
|
105 |
'LunarLander-v2':{'title':" The Lunar Lander π Leaderboard π",'data':get_data_per_env('LunarLander-v2')}
|
106 |
}
|
107 |
|
108 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
109 |
block = gr.Blocks()
|
110 |
with block:
|
111 |
|
@@ -134,9 +167,11 @@ with block:
|
|
134 |
# {name_leaderboard}
|
135 |
""".format(name_leaderboard = RL_DETAILS[rl_env]['title'])
|
136 |
|
137 |
-
|
138 |
-
gr.
|
139 |
-
gr.
|
|
|
|
|
140 |
|
141 |
|
142 |
block.launch()
|
|
|
38 |
result = meta["model-index"][0]["results"]
|
39 |
metrics = result[0]["metrics"]
|
40 |
accuracy = metrics[0]["value"]
|
41 |
+
#print("ACCURACY", accuracy)
|
42 |
return accuracy
|
43 |
|
44 |
# We keep the worst case episode
|
|
|
64 |
row["User"] = user_id
|
65 |
row["Model"] = model_id
|
66 |
accuracy = parse_metrics_accuracy(meta)
|
67 |
+
#print("RETURNED ACCURACY", accuracy)
|
68 |
mean_reward, std_reward = parse_rewards(accuracy)
|
69 |
+
#print("MEAN REWARD", mean_reward)
|
70 |
row["Results"] = mean_reward - std_reward
|
71 |
row["Mean Reward"] = mean_reward
|
72 |
row["Std Reward"] = std_reward
|
|
|
86 |
table_html = dataframe.to_html(escape=False, index=False)
|
87 |
table_html = table_html.replace("<table>", '<table style="width: 100%; margin: auto; border:0.5px solid; border-spacing: 7px 0px">') # center-align the headers
|
88 |
|
89 |
+
table_html = table_html.replace("<thead>", '<thead align="left">') # left-align the headers
|
90 |
|
91 |
+
table_html = "<div style='text-align: left ; width:100%'>"+table_html+"</div>"
|
92 |
return table_html,dataframe,dataframe.empty
|
93 |
else:
|
94 |
html = """<div style="color: green">
|
|
|
100 |
|
101 |
|
102 |
RL_ENVS = ['LunarLander-v2','CarRacing-v0','MountainCar-v0']
|
103 |
+
|
104 |
RL_DETAILS ={'CarRacing-v0':{'title':" The Car Racing ποΈ Leaderboard π",'data':get_data_per_env('CarRacing-v0')},
|
105 |
'MountainCar-v0':{'title':"The Mountain Car β°οΈ π Leaderboard π",'data':get_data_per_env('MountainCar-v0')},
|
106 |
'LunarLander-v2':{'title':" The Lunar Lander π Leaderboard π",'data':get_data_per_env('LunarLander-v2')}
|
107 |
}
|
108 |
|
109 |
|
110 |
+
def reload_leaderboard(rl_env):
|
111 |
+
#import pdb;pdb.set_trace()
|
112 |
+
global RL_DETAILS
|
113 |
+
RL_DETAILS[rl_env]['data'] = get_data_per_env(rl_env)
|
114 |
+
|
115 |
+
data_html,data_dataframe,is_empty = RL_DETAILS[rl_env]['data']
|
116 |
+
|
117 |
+
if not is_empty:
|
118 |
+
markdown = """
|
119 |
+
# {name_leaderboard}
|
120 |
+
|
121 |
+
This is a leaderboard of **{len_dataframe}** agents playing {env_name} π©βπ.
|
122 |
+
|
123 |
+
We use lower bound result to sort the models: mean_reward - std_reward.
|
124 |
+
|
125 |
+
You can click on the model's name to be redirected to its model card which includes documentation.
|
126 |
+
|
127 |
+
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.
|
128 |
+
|
129 |
+
|
130 |
+
""".format(len_dataframe = len(data_dataframe),env_name = rl_env,name_leaderboard = RL_DETAILS[rl_env]['title'])
|
131 |
+
|
132 |
+
else:
|
133 |
+
markdown = """
|
134 |
+
# {name_leaderboard}
|
135 |
+
""".format(name_leaderboard = RL_DETAILS[rl_env]['title'])
|
136 |
+
|
137 |
+
return markdown,data_html
|
138 |
+
|
139 |
+
|
140 |
+
|
141 |
+
|
142 |
block = gr.Blocks()
|
143 |
with block:
|
144 |
|
|
|
167 |
# {name_leaderboard}
|
168 |
""".format(name_leaderboard = RL_DETAILS[rl_env]['title'])
|
169 |
|
170 |
+
reload = gr.Button('Reload Leaderboard')
|
171 |
+
#env_state = gr.State(rl_env)
|
172 |
+
output_markdown = gr.Markdown(markdown)
|
173 |
+
output_html = gr.HTML(data_html)
|
174 |
+
reload.click(reload_leaderboard,inputs=[rl_env],outputs=[output_markdown,output_html])
|
175 |
|
176 |
|
177 |
block.launch()
|