chrisjay commited on
Commit
fb67b80
β€’
1 Parent(s): 059d8f0

initial files

Browse files
Files changed (1) hide show
  1. app.py +27 -17
app.py CHANGED
@@ -1,24 +1,22 @@
1
  import requests
2
- import json
3
  import pandas as pd
4
  from tqdm.auto import tqdm
5
 
6
  import gradio as gr
7
- #import streamlit as st
8
  from huggingface_hub import HfApi, hf_hub_download
9
  from huggingface_hub.repocard import metadata_load
10
- #import streamlit.components.v1 as components
11
 
12
  # Based on Omar Sanseviero work
13
  # Make model clickable link
14
  def make_clickable_model(model_name):
15
  link = "https://huggingface.co/" + model_name
16
- return f'<a target="_blank" href="{link}">{model_name}</a>'
17
 
18
  # Make user clickable link
19
  def make_clickable_user(user_id):
20
  link = "https://huggingface.co/" + user_id
21
- return f'<a target="_blank" href="{link}">{user_id}</a>'
22
 
23
  def get_model_ids(rl_env):
24
  api = HfApi()
@@ -80,14 +78,17 @@ def get_data_per_env(rl_env):
80
  dataframe = get_data(rl_env)
81
  dataframe = dataframe.fillna("")
82
 
83
- #import pdb; pdb.set_trace()
84
  if not dataframe.empty:
85
  # turn the model ids into clickable links
86
  dataframe["User"] = dataframe["User"].apply(make_clickable_user)
87
  dataframe["Model"] = dataframe["Model"].apply(make_clickable_model)
88
  dataframe = dataframe.sort_values(by=['Results'], ascending=False)
89
  table_html = dataframe.to_html(escape=False, index=False)
90
- table_html = table_html.replace("<th>", '<th align="left">') # left-align the headers
 
 
 
 
91
  return table_html,dataframe,dataframe.empty
92
  else:
93
  html = """<div style="color: green">
@@ -98,9 +99,9 @@ def get_data_per_env(rl_env):
98
 
99
 
100
 
101
- RL_ENVS = ['CarRacing-v0','MountainCar-v0','LunarLander-v2']
102
- RL_DETAILS ={'CarRacing-v0':{'title':" The Car Racing πŸŒ• Leaderboard πŸš€",'data':get_data_per_env('CarRacing-v0')},
103
- 'MountainCar-v0':{'title':"The Mountain Car πŸŒ• Leaderboard πŸš€",'data':get_data_per_env('MountainCar-v0')},
104
  'LunarLander-v2':{'title':" The Lunar Lander πŸŒ• Leaderboard πŸš€",'data':get_data_per_env('LunarLander-v2')}
105
  }
106
 
@@ -113,18 +114,27 @@ with block:
113
  with gr.TabItem(rl_env):
114
  data_html,data_dataframe,is_empty = RL_DETAILS[rl_env]['data']
115
 
116
- markdown = """
117
- # {name_leaderboard}
 
 
 
 
 
 
 
118
 
119
- This is a leaderboard of {len_dataframe}** agents playing {env_name} πŸ‘©β€πŸš€.
120
 
121
- We use lower bound result to sort the models: mean_reward - std_reward.
122
 
123
- You can click on the model's name to be redirected to its model card which includes documentation.
124
 
125
- You want to try your model? Read this Unit 1 of Deep Reinforcement Learning Class: https://github.com/huggingface/deep-rl-class/blob/Unit1/unit1/README.md.
 
 
 
126
 
127
- """.format(len_dataframe = len(data_dataframe),env_name = rl_env,name_leaderboard = RL_DETAILS[rl_env]['title'])
128
  gr.Markdown(markdown)
129
  gr.HTML(data_html)
130
 
 
1
  import requests
 
2
  import pandas as pd
3
  from tqdm.auto import tqdm
4
 
5
  import gradio as gr
 
6
  from huggingface_hub import HfApi, hf_hub_download
7
  from huggingface_hub.repocard import metadata_load
8
+
9
 
10
  # Based on Omar Sanseviero work
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()
 
78
  dataframe = get_data(rl_env)
79
  dataframe = dataframe.fillna("")
80
 
 
81
  if not dataframe.empty:
82
  # turn the model ids into clickable links
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="center">') # center-align the headers
90
+
91
+ table_html = "<div style='text-align: center ; width:100%'>"+table_html+"</div>"
92
  return table_html,dataframe,dataframe.empty
93
  else:
94
  html = """<div style="color: green">
 
99
 
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
 
 
114
  with gr.TabItem(rl_env):
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
+
138
  gr.Markdown(markdown)
139
  gr.HTML(data_html)
140