pkalkman's picture
moved environments to a json file and pointed to personal dataset
f8e1881
raw
history blame
2.82 kB
import os
import json
import requests
import datetime
import gradio as gr
import pandas as pd
from huggingface_hub import HfApi, hf_hub_download, snapshot_download
from huggingface_hub.repocard import metadata_load
from apscheduler.schedulers.background import BackgroundScheduler
from tqdm.contrib.concurrent import thread_map
from utils import *
DATASET_REPO_URL = "https://huggingface.co/datasets/pkalkman/drlc-leaderboard-data"
DATASET_REPO_ID = "pkalkman/drlc-leaderboard-data"
HF_TOKEN = os.environ.get("HF_TOKEN")
block = gr.Blocks()
api = HfApi(token=HF_TOKEN)
# Read the environments from the JSON file
with open('envs.json', 'r') as f:
rl_envs = json.load(f)
def download_leaderboard_dataset():
# Download the dataset from the Hugging Face Hub
path = snapshot_download(repo_id=DATASET_REPO_ID, repo_type="dataset")
return path
def get_data(rl_env, path) -> pd.DataFrame:
"""
Get data from rl_env CSV file and return as DataFrame
"""
csv_path = os.path.join(path, rl_env + ".csv")
data = pd.read_csv(csv_path)
return data
def get_last_refresh_time(path) -> str:
"""
Get the latest modification time of any CSV file in the dataset path
"""
# Get list of all CSV files in the dataset path
csv_files = [os.path.join(path, f) for f in os.listdir(path) if f.endswith('.csv')]
# Get the latest modification time
latest_time = max([os.path.getmtime(f) for f in csv_files])
# Convert to human-readable format
return datetime.datetime.fromtimestamp(latest_time).strftime('%Y-%m-%d %H:%M:%S')
with block:
path_ = download_leaderboard_dataset()
# Get the last refresh time
last_refresh_time = get_last_refresh_time(path_)
gr.Markdown(f"""
# πŸ† Deep Reinforcement Learning Course Leaderboard πŸ†
Presenting the latest leaderboard from the Hugging Face Deep RL Course - refresh ({last_refresh_time}).
""")
for i in range(0, len(rl_envs)):
rl_env = rl_envs[i]
with gr.TabItem(rl_env["rl_env_beautiful"]):
with gr.Row():
markdown = f"""
# {rl_env['rl_env_beautiful']}
### Leaderboard for {rl_env['rl_env_beautiful']}
"""
gr.Markdown(markdown)
with gr.Row():
# Display the data for this RL environment
data = get_data(rl_env["rl_env"], path_)
gr.Dataframe(
value=data,
headers=["Ranking πŸ†", "User πŸ€—", "Model id πŸ€–", "Results", "Mean Reward", "Std Reward"],
datatype=["number", "markdown", "markdown", "number", "number", "number"],
row_count=(100, 'fixed')
)
block.launch()