Spaces:
Sleeping
Sleeping
File size: 1,158 Bytes
6f5cc9b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | from dataclasses import asdict
from fastapi import APIRouter, HTTPException
from typing import Any, Dict, List
from app.config.benchmarks import EEG_BENCHMARKS
router = APIRouter()
# Fields that are internal implementation details, not exposed via API
_INTERNAL_FIELDS = {"accuracy_field"}
def _benchmark_to_dict(key: str, benchmark) -> Dict[str, Any]:
"""Convert a BenchmarkInfo dataclass to a JSON-serializable dict."""
d = asdict(benchmark)
for field in _INTERNAL_FIELDS:
d.pop(field, None)
d["key"] = key
return d
@router.get("")
async def list_benchmarks() -> List[Dict[str, Any]]:
"""Return all registered EEG benchmarks with metadata."""
return [_benchmark_to_dict(k, b) for k, b in EEG_BENCHMARKS.items()]
@router.get("/{key}")
async def get_benchmark(key: str) -> Dict[str, Any]:
"""Return a single benchmark's details by key."""
benchmark = EEG_BENCHMARKS.get(key)
if not benchmark:
raise HTTPException(
status_code=404,
detail=f"Benchmark '{key}' not found. Available: {list(EEG_BENCHMARKS.keys())}",
)
return _benchmark_to_dict(key, benchmark)
|