TheXeos commited on
Commit
b62b9e0
1 Parent(s): c2523c1

Switch to remove dataset storage

Browse files
Files changed (4) hide show
  1. app.py +15 -8
  2. background_task.py +14 -3
  3. env_elos/elo.csv +0 -5
  4. match_history/.gitkeep +0 -0
app.py CHANGED
@@ -2,7 +2,7 @@ import json
2
  import requests
3
  from datasets import load_dataset
4
  import gradio as gr
5
- from huggingface_hub import HfApi, hf_hub_download
6
  from huggingface_hub.repocard import metadata_load
7
  import pandas as pd
8
  from matchmaking import *
@@ -10,19 +10,24 @@ from background_task import init_matchmaking
10
  from apscheduler.schedulers.background import BackgroundScheduler
11
 
12
 
 
 
 
 
 
 
13
  block = gr.Blocks()
14
- env = [
15
- {
16
- "name": "Soccer",
17
- "global": None,
18
- },
19
- ]
20
  matchmaking = Matchmaking()
 
21
 
22
  scheduler = BackgroundScheduler()
23
  scheduler.add_job(func=init_matchmaking, trigger="interval", seconds=15000)
24
  scheduler.start()
25
 
 
 
 
 
26
 
27
  def update_elos():
28
  matchmaking.read_history()
@@ -31,7 +36,9 @@ def update_elos():
31
 
32
 
33
  def get_elo_data() -> pd.DataFrame:
34
- data = pd.read_csv(f"env_elos/elo.csv")
 
 
35
  return data
36
 
37
 
 
2
  import requests
3
  from datasets import load_dataset
4
  import gradio as gr
5
+ from huggingface_hub import HfApi, hf_hub_download, Repository
6
  from huggingface_hub.repocard import metadata_load
7
  import pandas as pd
8
  from matchmaking import *
 
10
  from apscheduler.schedulers.background import BackgroundScheduler
11
 
12
 
13
+ DATASET_REPO_URL = "https://huggingface.co/datasets/CarlCochet/BotFightData"
14
+ ELO_FILENAME = "elo.csv"
15
+ ELO_DIR = "soccer_elo"
16
+ ELO_FILE = os.path.join(ELO_DIR, ELO_FILENAME)
17
+ HF_TOKEN = os.environ.get("HF_TOKEN")
18
+
19
  block = gr.Blocks()
 
 
 
 
 
 
20
  matchmaking = Matchmaking()
21
+ api = HfApi()
22
 
23
  scheduler = BackgroundScheduler()
24
  scheduler.add_job(func=init_matchmaking, trigger="interval", seconds=15000)
25
  scheduler.start()
26
 
27
+ repo = Repository(
28
+ local_dir=ELO_DIR, clone_from=DATASET_REPO_URL, use_auth_token=HF_TOKEN
29
+ )
30
+
31
 
32
  def update_elos():
33
  matchmaking.read_history()
 
36
 
37
 
38
  def get_elo_data() -> pd.DataFrame:
39
+ hf_hub_download(repo_id="CarlCochet/BotFightData", filename=ELO_FILENAME, subfolder=ELO_DIR)
40
+ with open(ELO_FILE, "r") as f:
41
+ data = pd.read_csv(f)
42
  return data
43
 
44
 
background_task.py CHANGED
@@ -1,10 +1,15 @@
 
1
  import random
2
  import pandas as pd
3
  from datetime import datetime
4
  from huggingface_hub import HfApi
5
 
6
 
7
- env = "Soccer"
 
 
 
 
8
 
9
 
10
  class Model:
@@ -62,7 +67,6 @@ class Matchmaking:
62
  self.matches["model2"].append(model2.name)
63
  self.matches["result"].append(result)
64
  self.matches["datetime"].append(datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f"))
65
- self.matches["env"].append(env)
66
 
67
  def compute_elo(self, model1, model2, result):
68
  """ Compute the new elo for each model based on a match result. """
@@ -106,7 +110,14 @@ class Matchmaking:
106
  data_dict["games_played"].append(model.games_played)
107
 
108
  df = pd.DataFrame(data_dict)
109
- df.to_csv('env_elos/elo.csv', index=False)
 
 
 
 
 
 
 
110
  df_matches = pd.DataFrame(self.matches)
111
  date = datetime.now()
112
  df_matches.to_csv(f"match_history/{date.strftime('%Y-%m-%d_%H-%M-%S_%f')}.csv", index=False)
 
1
+ import os
2
  import random
3
  import pandas as pd
4
  from datetime import datetime
5
  from huggingface_hub import HfApi
6
 
7
 
8
+ DATASET_REPO_URL = "https://huggingface.co/datasets/CarlCochet/BotFightData"
9
+ ELO_FILENAME = "elo.csv"
10
+ ELO_DIR = "soccer_elo"
11
+ ELO_FILE = os.path.join(ELO_DIR, ELO_FILENAME)
12
+ HF_TOKEN = os.environ.get("HF_TOKEN")
13
 
14
 
15
  class Model:
 
67
  self.matches["model2"].append(model2.name)
68
  self.matches["result"].append(result)
69
  self.matches["datetime"].append(datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f"))
 
70
 
71
  def compute_elo(self, model1, model2, result):
72
  """ Compute the new elo for each model based on a match result. """
 
110
  data_dict["games_played"].append(model.games_played)
111
 
112
  df = pd.DataFrame(data_dict)
113
+ fileobj = open('env_elos/elo.csv', 'w')
114
+ df.to_csv(fileobj, index=False)
115
+ api.upload_file(
116
+ fileobj,
117
+ "env_elos/elo.csv",
118
+ "CarlCochet/BotFights",
119
+ "Update elos",
120
+ )
121
  df_matches = pd.DataFrame(self.matches)
122
  date = datetime.now()
123
  df_matches.to_csv(f"match_history/{date.strftime('%Y-%m-%d_%H-%M-%S_%f')}.csv", index=False)
env_elos/elo.csv DELETED
@@ -1,5 +0,0 @@
1
- rank,author,model,elo,games_played
2
- 1,CarlCochet,model3,1431,4
3
- 2,CarlCochet,model1,1234,8
4
- 3,CarlCochet,model4,1200,0
5
- 4,CarlCochet,model2,1000,5
 
 
 
 
 
 
match_history/.gitkeep DELETED
File without changes