Spaces:
Sleeping
Sleeping
Download backend/app/api/compare.py from Adisri99/ClusterBuster-API: direct link, hf CLI and curl.
- Browser
- Download file 1.23 kB
-
https://huggingface.co/spaces/Adisri99/ClusterBuster-API/resolve/main/backend/app/api/compare.py
- Command line
-
hf download hf://spaces/Adisri99/ClusterBuster-API/backend/app/api/compare.py
-
curl -L -o compare.py https://huggingface.co/spaces/Adisri99/ClusterBuster-API/resolve/main/backend/app/api/compare.py
1.23 kB
| import json | |
| from fastapi import APIRouter, Depends, Query | |
| from sqlalchemy.orm import Session | |
| from backend.app.db import get_db | |
| from backend.app.repositories.experiment_repo import get_experiments_by_ids, list_experiments | |
| router = APIRouter(tags=["compare"]) | |
| def compare_experiments(experiment_ids: str | None = Query(default=None), db: Session = Depends(get_db)): | |
| if experiment_ids: | |
| ids = [x.strip() for x in experiment_ids.split(",") if x.strip()] | |
| experiments = get_experiments_by_ids(db, ids) | |
| else: | |
| experiments = list_experiments(db) | |
| return { | |
| "experiments": [ | |
| { | |
| "experiment_id": exp.id, | |
| "dataset_id": exp.dataset_id, | |
| "algorithm": exp.algorithm, | |
| "status": exp.status, | |
| "config": json.loads(exp.config_json) if exp.config_json else {}, | |
| "metrics": json.loads(exp.metrics_json) if exp.metrics_json else {}, | |
| "summary": json.loads(exp.summary_json) if exp.summary_json else {}, | |
| "runtime_ms": exp.runtime_ms, | |
| "error_message": exp.error_message, | |
| } | |
| for exp in experiments | |
| ] | |
| } | |