chrisjay commited on
Commit
6867483
1 Parent(s): e5d72c9

loading all data on block reload

Browse files
Files changed (1) hide show
  1. app.py +15 -11
app.py CHANGED
@@ -38,7 +38,6 @@ 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 +63,7 @@ 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
@@ -84,8 +81,6 @@ def get_data_per_env(rl_env):
84
  dataframe["Model"] = dataframe["Model"].apply(make_clickable_model)
85
  dataframe = dataframe.sort_values(by=['Results'], ascending=False)
86
  table_html = dataframe.to_html(escape=False, index=False,justify = 'left')
87
-
88
- #table_html = table_html.replace("<thead>", '<thead align="left">') # left-align the headers
89
  return table_html,dataframe,dataframe.empty
90
  else:
91
  html = """<div style="color: green">
@@ -130,12 +125,19 @@ def get_info_display(len_dataframe,env_name,name_leaderboard,is_empty):
130
  """.format(name_leaderboard = name_leaderboard)
131
  return markdown
132
 
 
 
 
 
 
 
 
 
 
133
  def reload_leaderboard(rl_env):
134
  global RL_DETAILS
135
- RL_DETAILS[rl_env]['data'] = get_data_per_env(rl_env)
136
-
137
  data_html,data_dataframe,is_empty = RL_DETAILS[rl_env]['data']
138
- data_html = data_html.replace('thead align="left"', '<thead align="left" style="color:red">') # left-align the headers
139
 
140
  markdown = get_info_display(len(data_dataframe),rl_env,RL_DETAILS[rl_env]['title'],is_empty)
141
 
@@ -146,17 +148,19 @@ with open('app.css','r') as f:
146
 
147
  block = gr.Blocks(css=BLOCK_CSS)
148
  with block:
 
149
 
150
  with gr.Tabs():
151
  for rl_env in RL_ENVS:
152
- with gr.TabItem(rl_env):
153
  data_html,data_dataframe,is_empty = RL_DETAILS[rl_env]['data']
154
  markdown = get_info_display(len(data_dataframe),rl_env,RL_DETAILS[rl_env]['title'],is_empty)
155
- reload = gr.Button('Reload Leaderboard')
156
  env_state =gr.Variable(default_value=rl_env)
157
  output_markdown = gr.HTML(markdown)
 
 
158
  output_html = gr.HTML(data_html)
 
159
  reload.click(reload_leaderboard,inputs=[env_state],outputs=[output_markdown,output_html])
160
-
161
 
162
  block.launch()
 
38
  result = meta["model-index"][0]["results"]
39
  metrics = result[0]["metrics"]
40
  accuracy = metrics[0]["value"]
 
41
  return accuracy
42
 
43
  # We keep the worst case episode
 
63
  row["User"] = user_id
64
  row["Model"] = model_id
65
  accuracy = parse_metrics_accuracy(meta)
 
66
  mean_reward, std_reward = parse_rewards(accuracy)
 
67
  row["Results"] = mean_reward - std_reward
68
  row["Mean Reward"] = mean_reward
69
  row["Std Reward"] = std_reward
 
81
  dataframe["Model"] = dataframe["Model"].apply(make_clickable_model)
82
  dataframe = dataframe.sort_values(by=['Results'], ascending=False)
83
  table_html = dataframe.to_html(escape=False, index=False,justify = 'left')
 
 
84
  return table_html,dataframe,dataframe.empty
85
  else:
86
  html = """<div style="color: green">
 
125
  """.format(name_leaderboard = name_leaderboard)
126
  return markdown
127
 
128
+ def reload_all_data():
129
+
130
+ print(f'Loading all data...')
131
+ global RL_DETAILS,RL_ENVS
132
+
133
+ for rl_env in RL_ENVS:
134
+ RL_DETAILS[rl_env]['data'] = get_data_per_env(rl_env)
135
+
136
+
137
  def reload_leaderboard(rl_env):
138
  global RL_DETAILS
139
+
 
140
  data_html,data_dataframe,is_empty = RL_DETAILS[rl_env]['data']
 
141
 
142
  markdown = get_info_display(len(data_dataframe),rl_env,RL_DETAILS[rl_env]['title'],is_empty)
143
 
 
148
 
149
  block = gr.Blocks(css=BLOCK_CSS)
150
  with block:
151
+ block.load(reload_all_data,[],[])
152
 
153
  with gr.Tabs():
154
  for rl_env in RL_ENVS:
155
+ with gr.TabItem(rl_env) as rl_tab:
156
  data_html,data_dataframe,is_empty = RL_DETAILS[rl_env]['data']
157
  markdown = get_info_display(len(data_dataframe),rl_env,RL_DETAILS[rl_env]['title'],is_empty)
 
158
  env_state =gr.Variable(default_value=rl_env)
159
  output_markdown = gr.HTML(markdown)
160
+ reload = gr.Button('Reload Leaderboard')
161
+
162
  output_html = gr.HTML(data_html)
163
+
164
  reload.click(reload_leaderboard,inputs=[env_state],outputs=[output_markdown,output_html])
 
165
 
166
  block.launch()