Spaces:
Runtime error
Runtime error
Download app/api/feedback.py from devmurtaza/RastaAI: direct link, hf CLI and curl.
- Browser
- Download file 1.25 kB
-
https://huggingface.co/spaces/devmurtaza/RastaAI/resolve/main/app/api/feedback.py
- Command line
-
hf download hf://spaces/devmurtaza/RastaAI/app/api/feedback.py
-
curl -L -o feedback.py https://huggingface.co/spaces/devmurtaza/RastaAI/resolve/main/app/api/feedback.py
1.25 kB
| """User feedback collection - feeds future retraining.""" | |
| from __future__ import annotations | |
| from fastapi import APIRouter, Depends, HTTPException | |
| from sqlalchemy.ext.asyncio import AsyncSession | |
| from sqlalchemy import select | |
| from app.database import get_db | |
| from app.models.db_models import RouteFeedback, RoutePrediction | |
| from app.schemas.route import FeedbackRequest | |
| router = APIRouter(tags=["feedback"]) | |
| async def submit_feedback(req: FeedbackRequest, db: AsyncSession = Depends(get_db)) -> dict: | |
| prediction_id = None | |
| stmt = select(RoutePrediction).where(RoutePrediction.chosen_route_id == req.route_id) | |
| pred = (await db.execute(stmt)).scalar_one_or_none() | |
| if pred: | |
| prediction_id = pred.id | |
| if req.actual_eta_minutes is not None: | |
| pred.eta_actual_min = req.actual_eta_minutes | |
| fb = RouteFeedback( | |
| prediction_id=prediction_id, | |
| route_id=req.route_id, | |
| user_id=req.user_id, | |
| actual_eta_min=req.actual_eta_minutes, | |
| actual_fuel_l=req.actual_fuel_liters, | |
| rating=req.rating, | |
| completed=req.completed, | |
| notes=req.notes, | |
| ) | |
| db.add(fb) | |
| return {"ok": True, "linked_prediction_id": prediction_id} | |