Spaces:
Runtime error
Runtime error
Cleanup and run in headless mode
Browse files- app.py +1 -7
- background_task.py +19 -3
app.py
CHANGED
@@ -1,14 +1,8 @@
|
|
1 |
-
import json
|
2 |
-
import requests
|
3 |
-
from datasets import load_dataset
|
4 |
import gradio as gr
|
5 |
-
from huggingface_hub import HfApi
|
6 |
-
from huggingface_hub.repocard import metadata_load
|
7 |
-
import pandas as pd
|
8 |
from matchmaking import *
|
9 |
from background_task import init_matchmaking, get_elo_data
|
10 |
from apscheduler.schedulers.background import BackgroundScheduler
|
11 |
-
import asyncio
|
12 |
|
13 |
matchmaking = Matchmaking()
|
14 |
api = HfApi()
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from huggingface_hub import HfApi
|
|
|
|
|
3 |
from matchmaking import *
|
4 |
from background_task import init_matchmaking, get_elo_data
|
5 |
from apscheduler.schedulers.background import BackgroundScheduler
|
|
|
6 |
|
7 |
matchmaking = Matchmaking()
|
8 |
api = HfApi()
|
background_task.py
CHANGED
@@ -1,7 +1,5 @@
|
|
1 |
import os
|
2 |
-
import time
|
3 |
import random
|
4 |
-
import asyncio
|
5 |
import subprocess
|
6 |
import pandas as pd
|
7 |
from datetime import datetime
|
@@ -155,13 +153,15 @@ class Matchmaking:
|
|
155 |
|
156 |
def match(model1, model2):
|
157 |
"""
|
|
|
|
|
158 |
:param model1: First Model object
|
159 |
:param model2: Second Model object
|
160 |
:return: match result (0: model1 lost, 0.5: draw, 1: model1 won)
|
161 |
"""
|
162 |
model1_id = model1.author + "/" + model1.name
|
163 |
model2_id = model2.author + "/" + model2.name
|
164 |
-
subprocess.run(["./SoccerTows.x86_64", "-model1", model1_id, "-model2", model2_id])
|
165 |
print(f"Match {model1_id} against {model2_id} ended.")
|
166 |
model1.games_played += 1
|
167 |
model2.games_played += 1
|
@@ -169,6 +169,8 @@ def match(model1, model2):
|
|
169 |
|
170 |
def get_models_list() -> list:
|
171 |
"""
|
|
|
|
|
172 |
:return: list of Model objects
|
173 |
"""
|
174 |
models = []
|
@@ -187,12 +189,26 @@ def get_models_list() -> list:
|
|
187 |
|
188 |
|
189 |
def get_elo_data() -> pd.DataFrame:
|
|
|
|
|
|
|
|
|
|
|
190 |
repo.git_pull()
|
191 |
data = pd.read_csv(os.path.join(DATASET_REPO_URL, "resolve", "main", ELO_FILENAME))
|
192 |
return data
|
193 |
|
194 |
|
195 |
def init_matchmaking():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
196 |
models = get_models_list()
|
197 |
matchmaking = Matchmaking(models)
|
198 |
matchmaking.run()
|
|
|
1 |
import os
|
|
|
2 |
import random
|
|
|
3 |
import subprocess
|
4 |
import pandas as pd
|
5 |
from datetime import datetime
|
|
|
153 |
|
154 |
def match(model1, model2):
|
155 |
"""
|
156 |
+
Simulate a match between two models using the Unity environment.
|
157 |
+
|
158 |
:param model1: First Model object
|
159 |
:param model2: Second Model object
|
160 |
:return: match result (0: model1 lost, 0.5: draw, 1: model1 won)
|
161 |
"""
|
162 |
model1_id = model1.author + "/" + model1.name
|
163 |
model2_id = model2.author + "/" + model2.name
|
164 |
+
subprocess.run(["./SoccerTows.x86_64", "-model1", model1_id, "-model2", model2_id, "-nographics", "-batchmode"])
|
165 |
print(f"Match {model1_id} against {model2_id} ended.")
|
166 |
model1.games_played += 1
|
167 |
model2.games_played += 1
|
|
|
169 |
|
170 |
def get_models_list() -> list:
|
171 |
"""
|
172 |
+
Get the list of models from the hub and the ELO file.
|
173 |
+
|
174 |
:return: list of Model objects
|
175 |
"""
|
176 |
models = []
|
|
|
189 |
|
190 |
|
191 |
def get_elo_data() -> pd.DataFrame:
|
192 |
+
"""
|
193 |
+
Get the ELO data from the hub for all the models that have played at least one game.
|
194 |
+
|
195 |
+
:return: ELO data as a pandas DataFrame
|
196 |
+
"""
|
197 |
repo.git_pull()
|
198 |
data = pd.read_csv(os.path.join(DATASET_REPO_URL, "resolve", "main", ELO_FILENAME))
|
199 |
return data
|
200 |
|
201 |
|
202 |
def init_matchmaking():
|
203 |
+
"""
|
204 |
+
Run the matchmaking algorithm and save the results to the hub.
|
205 |
+
|
206 |
+
1. Get the list of models from the hub and the ELO data
|
207 |
+
2. Match models together based on their ELO rating
|
208 |
+
3. Simulate the matches using Unity to get the match result
|
209 |
+
4. Compute the new ELO rating for each model
|
210 |
+
5. Save the results to the hub
|
211 |
+
"""
|
212 |
models = get_models_list()
|
213 |
matchmaking = Matchmaking(models)
|
214 |
matchmaking.run()
|