Download backend/app/api/datasets.py from sumandas/ostra: direct link, hf CLI and curl.
- Browser
- Download file 1.85 kB
-
https://huggingface.co/spaces/sumandas/ostra/resolve/main/backend/app/api/datasets.py
- Command line
-
hf download hf://spaces/sumandas/ostra/backend/app/api/datasets.py
-
curl -L -o datasets.py https://huggingface.co/spaces/sumandas/ostra/resolve/main/backend/app/api/datasets.py
1.85 kB
| from __future__ import annotations | |
| from typing import Literal | |
| from fastapi import APIRouter, HTTPException, Query | |
| from app.config import CURATED_MODELS, CURATED_RERANKERS, STARTER_PRESETS | |
| from app.engine.hardware import detect_hardware | |
| from app.engine.hf_hub import search_hf_datasets, search_hf_models | |
| from app.engine.ingest import inspect_hf_dataset | |
| from app.schemas import ( | |
| HFDatasetSearchResponse, | |
| HFInspectRequest, | |
| HFInspectResponse, | |
| HFModelSearchResponse, | |
| ) | |
| router = APIRouter(prefix="/api", tags=["datasets"]) | |
| def get_hardware(): | |
| return { | |
| "hardware": detect_hardware().model_dump(), | |
| "models": CURATED_MODELS, | |
| "rerankers": CURATED_RERANKERS, | |
| "presets": STARTER_PRESETS, | |
| } | |
| def search_datasets( | |
| q: str = Query(default="", max_length=120), | |
| limit: int = Query(default=12, ge=1, le=30), | |
| ): | |
| return search_hf_datasets(query=q, limit=limit) | |
| def search_models( | |
| q: str = Query(default="", max_length=120), | |
| task: Literal["embedding", "reranker"] = Query(default="embedding"), | |
| limit: int = Query(default=15, ge=1, le=30), | |
| ): | |
| return search_hf_models(query=q, task=task, limit=limit) | |
| def inspect_dataset(req: HFInspectRequest): | |
| try: | |
| return inspect_hf_dataset( | |
| dataset_id=req.dataset_id.strip(), | |
| config=req.config, | |
| split=req.split, | |
| sample_rows=req.sample_rows, | |
| ) | |
| except Exception as exc: | |
| raise HTTPException( | |
| status_code=400, | |
| detail=f"Failed to inspect Hugging Face dataset '{req.dataset_id}': {exc}", | |
| ) from exc | |