Spaces:
Runtime error
Runtime error
Commit ·
00a16d9
1
Parent(s): edc3d56
Create load_to_hub.py
Browse files- src/load_to_hub.py +56 -0
src/load_to_hub.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
import math
|
| 3 |
+
|
| 4 |
+
import pandas as pd
|
| 5 |
+
|
| 6 |
+
from src.assets.symbols import UP_ARROW, DOWN_ARROW
|
| 7 |
+
|
| 8 |
+
from src.tasks import TASKS, TASK_CODES, TASK_TO_METRIC
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def load_from_hub(fs, repo_path):
|
| 12 |
+
files = fs.glob(f"{repo_path}/**/*.json")
|
| 13 |
+
|
| 14 |
+
set_organization_models = {}
|
| 15 |
+
tasks = {}
|
| 16 |
+
|
| 17 |
+
for file in files:
|
| 18 |
+
organization, model, task = file.split("/")[-3:]
|
| 19 |
+
|
| 20 |
+
organization_model = f"{organization}/{model}"
|
| 21 |
+
task_code = task.replace(".json", "")
|
| 22 |
+
|
| 23 |
+
if task_code not in TASK_CODES:
|
| 24 |
+
continue
|
| 25 |
+
|
| 26 |
+
set_organization_models[organization_model] = 1
|
| 27 |
+
tasks[task_code] = 1
|
| 28 |
+
|
| 29 |
+
table = pd.DataFrame(
|
| 30 |
+
index=list(set_organization_models.keys()),
|
| 31 |
+
columns=["Organization", "Model"] + list(tasks.keys()),
|
| 32 |
+
data=None,
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
for file in files:
|
| 36 |
+
organization, model, task = file.split("/")[-3:]
|
| 37 |
+
|
| 38 |
+
organization_model = f"{organization}/{model}"
|
| 39 |
+
task_code = task.replace(".json", "")
|
| 40 |
+
|
| 41 |
+
if task_code not in TASK_CODES:
|
| 42 |
+
continue
|
| 43 |
+
|
| 44 |
+
data = json.loads(fs.open(file, "r").read())
|
| 45 |
+
|
| 46 |
+
result = round(data["results"][task_code][TASK_TO_METRIC[task_code]], 4)
|
| 47 |
+
|
| 48 |
+
table.loc[organization_model, task_code] = result
|
| 49 |
+
table.loc[organization_model, "Organization"] = organization
|
| 50 |
+
table.loc[organization_model, "Model"] = model
|
| 51 |
+
|
| 52 |
+
table.rename(columns={
|
| 53 |
+
task.code: f"{task.name} {UP_ARROW if task.higher_is_better else DOWN_ARROW}"
|
| 54 |
+
for task in TASKS}, inplace=True)
|
| 55 |
+
|
| 56 |
+
return table
|