Spaces:
Runtime error
Runtime error
Add loading / sending to hub
Browse files
main.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import random
|
2 |
import pandas as pd
|
3 |
from datetime import datetime
|
|
|
4 |
|
5 |
|
6 |
class Model:
|
@@ -37,7 +38,8 @@ class Matchmaking:
|
|
37 |
"model1": [],
|
38 |
"model2": [],
|
39 |
"result": [],
|
40 |
-
"datetime": []
|
|
|
41 |
}
|
42 |
|
43 |
def run(self):
|
@@ -58,6 +60,7 @@ class Matchmaking:
|
|
58 |
self.matches["model2"].append(model2.name)
|
59 |
self.matches["result"].append(result)
|
60 |
self.matches["datetime"].append(datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f"))
|
|
|
61 |
|
62 |
def compute_elo(self, model1, model2, result):
|
63 |
""" Compute the new elo for each model based on a match result. """
|
@@ -96,7 +99,13 @@ class Matchmaking:
|
|
96 |
df = pd.concat([df, pd.DataFrame([[model.name, model.elo]], columns=['name', 'elo'])])
|
97 |
df.to_csv('elo.csv', index=False)
|
98 |
df_matches = pd.DataFrame(self.matches)
|
99 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
100 |
|
101 |
|
102 |
def match(model1, model2) -> float:
|
@@ -120,7 +129,11 @@ def get_models_list() -> list:
|
|
120 |
:return: list of Model objects
|
121 |
"""
|
122 |
models = []
|
123 |
-
|
|
|
|
|
|
|
|
|
124 |
for i, row in data.iterrows():
|
125 |
models.append(Model(row["name"], row["elo"]))
|
126 |
return models
|
@@ -128,11 +141,12 @@ def get_models_list() -> list:
|
|
128 |
|
129 |
def init_matchmaking():
|
130 |
models = get_models_list()
|
131 |
-
matchmaking = Matchmaking(models)
|
132 |
matchmaking.run()
|
133 |
matchmaking.to_csv()
|
134 |
|
135 |
|
136 |
if __name__ == "__main__":
|
137 |
print("It's running!")
|
138 |
-
|
|
|
|
1 |
import random
|
2 |
import pandas as pd
|
3 |
from datetime import datetime
|
4 |
+
from huggingface_hub import hf_hub_download, HfApi
|
5 |
|
6 |
|
7 |
class Model:
|
|
|
38 |
"model1": [],
|
39 |
"model2": [],
|
40 |
"result": [],
|
41 |
+
"datetime": [],
|
42 |
+
"env": []
|
43 |
}
|
44 |
|
45 |
def run(self):
|
|
|
60 |
self.matches["model2"].append(model2.name)
|
61 |
self.matches["result"].append(result)
|
62 |
self.matches["datetime"].append(datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f"))
|
63 |
+
self.matches["env"].append(self.env)
|
64 |
|
65 |
def compute_elo(self, model1, model2, result):
|
66 |
""" Compute the new elo for each model based on a match result. """
|
|
|
99 |
df = pd.concat([df, pd.DataFrame([[model.name, model.elo]], columns=['name', 'elo'])])
|
100 |
df.to_csv('elo.csv', index=False)
|
101 |
df_matches = pd.DataFrame(self.matches)
|
102 |
+
date = datetime.now()
|
103 |
+
df_matches.to_csv(f"matches/{self.env}__{date.strftime('%Y-%m-%d_%H-%M-%S_%f')}.csv", index=False)
|
104 |
+
api.upload_file(
|
105 |
+
path_or_fileobj=f"matches/{self.env}__{date.strftime('%Y-%m-%d_%H-%M-%S_%f')}.csv",
|
106 |
+
path_in_repo=f"match_history/{self.env}__{date.strftime('%Y-%m-%d_%H-%M-%S_%f')}.csv",
|
107 |
+
repo_id="CarlCochet/BotFights"
|
108 |
+
)
|
109 |
|
110 |
|
111 |
def match(model1, model2) -> float:
|
|
|
129 |
:return: list of Model objects
|
130 |
"""
|
131 |
models = []
|
132 |
+
hf_hub_download(
|
133 |
+
repo_id="CarlCochet/BotFights",
|
134 |
+
filename="elo.csv",
|
135 |
+
)
|
136 |
+
data = pd.read_csv("elo.csv")
|
137 |
for i, row in data.iterrows():
|
138 |
models.append(Model(row["name"], row["elo"]))
|
139 |
return models
|
|
|
141 |
|
142 |
def init_matchmaking():
|
143 |
models = get_models_list()
|
144 |
+
matchmaking = Matchmaking(models, "snowball-fight")
|
145 |
matchmaking.run()
|
146 |
matchmaking.to_csv()
|
147 |
|
148 |
|
149 |
if __name__ == "__main__":
|
150 |
print("It's running!")
|
151 |
+
api = HfApi()
|
152 |
+
init_matchmaking()
|