chrisjay commited on
Commit
31d2bda
β€’
1 Parent(s): 7fa09dc

css designs to table and more

Browse files
Files changed (2) hide show
  1. app.css +32 -0
  2. app.py +41 -56
app.css ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ .infoPoint h1 {
3
+ font-size: 30px;
4
+ text-decoration: bold;
5
+
6
+ }
7
+
8
+ a {
9
+ text-decoration: underline;
10
+ color: #1f3b54 ;
11
+ }
12
+
13
+ table {
14
+
15
+ margin: 25px 0;
16
+ font-size: 0.9em;
17
+ font-family: sans-serif;
18
+ min-width: 400px;
19
+ box-shadow: 0 0 20px rgba(0, 0, 0, 0.15);
20
+ }
21
+
22
+ table th,
23
+ table td {
24
+ padding: 12px 15px;
25
+ }
26
+
27
+ tr {
28
+ text-align: left;
29
+ }
30
+ thead tr {
31
+ text-align: left;
32
+ }
app.py CHANGED
@@ -11,12 +11,12 @@ from huggingface_hub.repocard import metadata_load
11
  # Make model clickable link
12
  def make_clickable_model(model_name):
13
  link = "https://huggingface.co/" + model_name
14
- return f'<a style="text-decoration: underline; color: #1f3b54 " target="_blank" href="{link}">{model_name}</a>'
15
 
16
  # Make user clickable link
17
  def make_clickable_user(user_id):
18
  link = "https://huggingface.co/" + user_id
19
- return f'<a style="text-decoration: underline; color: #1f3b54 " target="_blank" href="{link}">{user_id}</a>'
20
 
21
  def get_model_ids(rl_env):
22
  api = HfApi()
@@ -83,12 +83,9 @@ def get_data_per_env(rl_env):
83
  dataframe["User"] = dataframe["User"].apply(make_clickable_user)
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)
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">
@@ -107,71 +104,59 @@ RL_DETAILS ={'CarRacing-v0':{'title':" The Car Racing 🏎️ Leaderboard πŸš€",
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
 
145
  with gr.Tabs():
146
  for rl_env in RL_ENVS:
147
  with gr.TabItem(rl_env):
148
  data_html,data_dataframe,is_empty = RL_DETAILS[rl_env]['data']
149
-
150
- if not is_empty:
151
- markdown = """
152
- # {name_leaderboard}
153
-
154
- This is a leaderboard of **{len_dataframe}** agents playing {env_name} πŸ‘©β€πŸš€.
155
-
156
- We use lower bound result to sort the models: mean_reward - std_reward.
157
-
158
- You can click on the model's name to be redirected to its model card which includes documentation.
159
-
160
- 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.
161
-
162
-
163
- """.format(len_dataframe = len(data_dataframe),env_name = rl_env,name_leaderboard = RL_DETAILS[rl_env]['title'])
164
-
165
- else:
166
- markdown = """
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()
 
11
  # Make model clickable link
12
  def make_clickable_model(model_name):
13
  link = "https://huggingface.co/" + model_name
14
+ return f'<a target="_blank" href="{link}">{model_name}</a>'
15
 
16
  # Make user clickable link
17
  def make_clickable_user(user_id):
18
  link = "https://huggingface.co/" + user_id
19
+ return f'<a target="_blank" href="{link}">{user_id}</a>'
20
 
21
  def get_model_ids(rl_env):
22
  api = HfApi()
 
83
  dataframe["User"] = dataframe["User"].apply(make_clickable_user)
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">
 
104
  }
105
 
106
 
107
+ def get_info_display(len_dataframe,env_name,name_leaderboard,is_empty):
 
 
 
 
 
 
108
  if not is_empty:
109
  markdown = """
110
+ <div class='infoPoint'>
111
+ <h1> {name_leaderboard} </h1>
112
+ <br>
113
+ <p> This is a leaderboard of <b>{len_dataframe}</b> agents playing {env_name} πŸ‘©β€πŸš€. </p>
114
+ <br>
115
+ <p> We use lower bound result to sort the models: mean_reward - std_reward. </p>
116
+ <br>
117
+ <p> You can click on the model's name to be redirected to its model card which includes documentation. </p>
118
+ <br>
119
+ <p> You want to try your model? Read this <a href="https://github.com/huggingface/deep-rl-class/blob/Unit1/unit1/README.md" target="_blank">Unit 1</a> of Deep Reinforcement Learning Class.
120
+ </p>
121
+ </div>
122
+ """.format(len_dataframe = len_dataframe,env_name = env_name,name_leaderboard = name_leaderboard)
123
 
124
  else:
125
  markdown = """
126
+ <div class='infoPoint'>
127
+ <h1> {name_leaderboard} </h1>
128
+ <br>
129
+ </div>
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
+
142
  return markdown,data_html
143
 
144
+ with open('app.css','r') as f:
145
+ BLOCK_CSS = f.read()
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()