Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Commit ·
e932bc6
1
Parent(s): 7f3a938
Cache for raw results data
Browse files
backend/app/services/leaderboard.py
CHANGED
|
@@ -17,6 +17,7 @@ import dateutil
|
|
| 17 |
import numpy as np
|
| 18 |
from huggingface_hub import snapshot_download
|
| 19 |
from app.services.models import ModelService
|
|
|
|
| 20 |
|
| 21 |
from app.config import (
|
| 22 |
RESULTS_CACHE,
|
|
@@ -228,8 +229,12 @@ class EvalResult:
|
|
| 228 |
)
|
| 229 |
|
| 230 |
class LeaderboardService:
|
|
|
|
| 231 |
def __init__(self):
|
| 232 |
self.model_service = ModelService()
|
|
|
|
|
|
|
|
|
|
| 233 |
pass
|
| 234 |
|
| 235 |
async def get_raw_eval_results(self, results_path: str, requests_path: str) -> list[EvalResult]:
|
|
@@ -269,13 +274,24 @@ class LeaderboardService:
|
|
| 269 |
|
| 270 |
|
| 271 |
async def fetch_raw_data(self) -> List[EvalResult]:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 272 |
"""Fetch raw leaderboard data from HuggingFace dataset"""
|
| 273 |
try:
|
| 274 |
logger.info(LogFormatter.section("FETCHING LEADERBOARD DATA"))
|
| 275 |
logger.info(LogFormatter.info(f"Loading dataset from {HF_ORGANIZATION}/contents"))
|
| 276 |
print("GETTING FROM %s" % HF_ORGANIZATION)
|
| 277 |
|
| 278 |
-
# TODO: cache
|
| 279 |
snapshot_download(
|
| 280 |
repo_id=RESULTS_REPO,
|
| 281 |
local_dir=RESULTS_CACHE,
|
|
|
|
| 17 |
import numpy as np
|
| 18 |
from huggingface_hub import snapshot_download
|
| 19 |
from app.services.models import ModelService
|
| 20 |
+
import time
|
| 21 |
|
| 22 |
from app.config import (
|
| 23 |
RESULTS_CACHE,
|
|
|
|
| 229 |
)
|
| 230 |
|
| 231 |
class LeaderboardService:
|
| 232 |
+
|
| 233 |
def __init__(self):
|
| 234 |
self.model_service = ModelService()
|
| 235 |
+
self.cached_raw_data = None
|
| 236 |
+
self.last_cache_update = 0
|
| 237 |
+
self.cache_ttl = cache_config.cache_ttl.total_seconds()
|
| 238 |
pass
|
| 239 |
|
| 240 |
async def get_raw_eval_results(self, results_path: str, requests_path: str) -> list[EvalResult]:
|
|
|
|
| 274 |
|
| 275 |
|
| 276 |
async def fetch_raw_data(self) -> List[EvalResult]:
|
| 277 |
+
|
| 278 |
+
# Check if cache needs refresh
|
| 279 |
+
current_time = time.time()
|
| 280 |
+
cache_age = current_time - self.last_cache_update
|
| 281 |
+
if not self.cached_raw_data:
|
| 282 |
+
return await self._refresh_raw_data()
|
| 283 |
+
elif cache_age > self.cache_ttl:
|
| 284 |
+
return await self._refresh_raw_data()
|
| 285 |
+
else:
|
| 286 |
+
return self.cached_raw_data
|
| 287 |
+
|
| 288 |
+
async def _refresh_raw_data(self) -> List[EvalResult]:
|
| 289 |
"""Fetch raw leaderboard data from HuggingFace dataset"""
|
| 290 |
try:
|
| 291 |
logger.info(LogFormatter.section("FETCHING LEADERBOARD DATA"))
|
| 292 |
logger.info(LogFormatter.info(f"Loading dataset from {HF_ORGANIZATION}/contents"))
|
| 293 |
print("GETTING FROM %s" % HF_ORGANIZATION)
|
| 294 |
|
|
|
|
| 295 |
snapshot_download(
|
| 296 |
repo_id=RESULTS_REPO,
|
| 297 |
local_dir=RESULTS_CACHE,
|