Download app/api/api.py from Sujith2121/drowsiness_detection_backend: direct link, hf CLI and curl.
- Browser
- Download file 779 Bytes
-
https://huggingface.co/spaces/Sujith2121/drowsiness_detection_backend/resolve/main/app/api/api.py
- Command line
-
hf download hf://spaces/Sujith2121/drowsiness_detection_backend/app/api/api.py
-
curl -L -o api.py https://huggingface.co/spaces/Sujith2121/drowsiness_detection_backend/resolve/main/app/api/api.py
779 Bytes
| from fastapi import APIRouter,Depends | |
| from sqlalchemy.orm import Session | |
| from app.db.session import SessionLocal | |
| from app.services.service import log_event,get_all_events,get_event_stats | |
| from app.schemas.schema import DrowsinessEventCreate,DrowsinessEventRead | |
| router=APIRouter() | |
| def get_db(): | |
| db=SessionLocal() | |
| try: | |
| yield db | |
| finally: | |
| db.close() | |
| def detect_event(event:DrowsinessEventCreate,db:Session=Depends(get_db)): | |
| return log_event(db,event=event) | |
| def list_events(db:Session=Depends(get_db),): | |
| return get_all_events(db) | |
| def stats(db:Session=Depends(get_db)): | |
| return get_event_stats(db) | |