import json import requests from datasets import load_dataset import gradio as gr from huggingface_hub import HfApi, hf_hub_download, Repository from huggingface_hub.repocard import metadata_load import pandas as pd from matchmaking import * from background_task import init_matchmaking, run_background_loop from apscheduler.schedulers.background import BackgroundScheduler import asyncio DATASET_REPO_URL = "https://huggingface.co/datasets/CarlCochet/BotFightData" ELO_FILENAME = "soccer_elo.csv" HF_TOKEN = os.environ.get("HF_TOKEN") repo = Repository( local_dir="soccer_elo", clone_from=DATASET_REPO_URL, use_auth_token=HF_TOKEN ) matchmaking = Matchmaking() api = HfApi() # scheduler = BackgroundScheduler() # scheduler.add_job(func=init_matchmaking, trigger="interval", seconds=15000) # scheduler.start() loop = asyncio.get_event_loop() loop.create_task(run_background_loop()) loop.run_forever() def get_elo_data() -> pd.DataFrame: repo.git_pull() data = pd.read_csv(os.path.join(DATASET_REPO_URL, "resolve", "main", ELO_FILENAME)) return data def update_elos(): matchmaking.read_history() matchmaking.compute_elo() matchmaking.save_elo_data() with gr.Blocks() as block: gr.Markdown(f""" # 🏆 The Deep Reinforcement Learning Course Leaderboard 🏆 This is the leaderboard of trained agents during the Deep Reinforcement Learning Course. A free course from beginner to expert. This is the Soccer environment leaderboard, use Ctrl+F to find your rank 🏆 We use an ELO rating to sort the models. You **can click on the model's name** to be redirected to its model card which includes documentation. 🤖 You want to try to train your agents? Sign up to the Hugging Face free Deep Reinforcement Learning Course 🤗 . You want to compare two agents? It's possible using this Spaces demo 👀 . 🔧 There is an **environment missing?** Please open an issue. """) with gr.Row(): output = gr.components.Dataframe( value=get_elo_data(), headers=["Ranking 🏆", "User 🤗", "Model id 🤖", "ELO 🚀", "Games played 🎮"], datatype=["number", "markdown", "markdown", "number", "number"] ) with gr.Row(): refresh = gr.Button("Refresh") refresh.click(get_elo_data, inputs=[], outputs=output) block.launch()