Spaces:
Sleeping
Sleeping
Download adsp/app/api/routes/reports.py from thanhnv2323/humanize-text-python: direct link, hf CLI and curl.
- Browser
- Download file 1.84 kB
-
https://huggingface.co/spaces/thanhnv2323/humanize-text-python/resolve/main/adsp/app/api/routes/reports.py
- Command line
-
hf download hf://spaces/thanhnv2323/humanize-text-python/adsp/app/api/routes/reports.py
-
curl -L -o reports.py https://huggingface.co/spaces/thanhnv2323/humanize-text-python/resolve/main/adsp/app/api/routes/reports.py
1.84 kB
| """Reporting API routes.""" | |
| from __future__ import annotations | |
| from typing import Any, Callable, Dict | |
| from pydantic import BaseModel, ConfigDict, Field | |
| class ReportGenerateRequest(BaseModel): | |
| model_config = ConfigDict( | |
| json_schema_extra={ | |
| "example": { | |
| "insights": { | |
| "top_drivers": ["taste", "price", "brand trust"], | |
| "summary": "Customer segment values consistency and practical value.", | |
| } | |
| } | |
| } | |
| ) | |
| insights: Dict[str, Any] = Field( | |
| default_factory=dict, | |
| description="Arbitrary insights payload to render into a report markdown file.", | |
| ) | |
| class ReportGenerateResponse(BaseModel): | |
| model_config = ConfigDict( | |
| json_schema_extra={"example": {"path": "reports/api/curious-connoisseurs_report.md"}} | |
| ) | |
| path: str = Field(description="Absolute or relative path of generated report file.") | |
| def register_report_routes( | |
| app: Any, | |
| *, | |
| get_services: Callable[..., Any], | |
| authorize: Callable[..., Any], | |
| ) -> None: | |
| from fastapi import Depends, Path | |
| def generate_report( | |
| payload: ReportGenerateRequest, | |
| persona_id: str = Path(description="Persona identifier used to name the report file."), | |
| services: Any = Depends(get_services), | |
| ) -> ReportGenerateResponse: | |
| report_path = services.reports.generate(persona_id=persona_id, insights=payload.insights) | |
| return ReportGenerateResponse(path=str(report_path)) | |