Spaces:
Sleeping
Sleeping
Fix leaderboard file path resolution relative to __file__
Browse files- leaderboard_io.py +15 -2
leaderboard_io.py
CHANGED
|
@@ -143,6 +143,19 @@ def build_leaderboard_row(
|
|
| 143 |
}
|
| 144 |
|
| 145 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 146 |
def read_leaderboard(
|
| 147 |
repo_id: Optional[str] = None,
|
| 148 |
local_file: str = "leaderboard.parquet",
|
|
@@ -154,7 +167,7 @@ def read_leaderboard(
|
|
| 154 |
if token is None:
|
| 155 |
token = os.environ.get("HF_TOKEN")
|
| 156 |
|
| 157 |
-
local_path =
|
| 158 |
|
| 159 |
if repo_id and token:
|
| 160 |
try:
|
|
@@ -201,7 +214,7 @@ def append_result(
|
|
| 201 |
if token is None:
|
| 202 |
token = os.environ.get("HF_TOKEN")
|
| 203 |
|
| 204 |
-
local_path =
|
| 205 |
df = read_leaderboard(repo_id=repo_id, local_file=local_file, token=token)
|
| 206 |
|
| 207 |
new_df = pd.concat([df, pd.DataFrame([row])], ignore_index=True)
|
|
|
|
| 143 |
}
|
| 144 |
|
| 145 |
|
| 146 |
+
DEFAULT_LOCAL_PARQUET = Path(__file__).resolve().parent / "leaderboard.parquet"
|
| 147 |
+
|
| 148 |
+
|
| 149 |
+
def _resolve_local_path(local_file: str) -> Path:
|
| 150 |
+
p = Path(local_file)
|
| 151 |
+
if p.exists():
|
| 152 |
+
return p
|
| 153 |
+
alt_p = Path(__file__).resolve().parent / local_file
|
| 154 |
+
if alt_p.exists():
|
| 155 |
+
return alt_p
|
| 156 |
+
return p
|
| 157 |
+
|
| 158 |
+
|
| 159 |
def read_leaderboard(
|
| 160 |
repo_id: Optional[str] = None,
|
| 161 |
local_file: str = "leaderboard.parquet",
|
|
|
|
| 167 |
if token is None:
|
| 168 |
token = os.environ.get("HF_TOKEN")
|
| 169 |
|
| 170 |
+
local_path = _resolve_local_path(local_file)
|
| 171 |
|
| 172 |
if repo_id and token:
|
| 173 |
try:
|
|
|
|
| 214 |
if token is None:
|
| 215 |
token = os.environ.get("HF_TOKEN")
|
| 216 |
|
| 217 |
+
local_path = _resolve_local_path(local_file)
|
| 218 |
df = read_leaderboard(repo_id=repo_id, local_file=local_file, token=token)
|
| 219 |
|
| 220 |
new_df = pd.concat([df, pd.DataFrame([row])], ignore_index=True)
|