Download app/api/sessions.py from Emeritus-21/Hand-written-text-recognition-testing: direct link, hf CLI and curl.
- Browser
- Download file 1.13 kB
-
https://huggingface.co/spaces/Emeritus-21/Hand-written-text-recognition-testing/resolve/main/app/api/sessions.py
- Command line
-
hf download hf://spaces/Emeritus-21/Hand-written-text-recognition-testing/app/api/sessions.py
-
curl -L -o sessions.py https://huggingface.co/spaces/Emeritus-21/Hand-written-text-recognition-testing/resolve/main/app/api/sessions.py
1.13 kB
| from fastapi import APIRouter, Depends, HTTPException | |
| from sqlalchemy.orm import Session | |
| from ..database import get_db | |
| from ..models.session import Session as DBSession, PatientIntake | |
| from ..schemas.session import SessionResponse, IntakeResponse | |
| import uuid | |
| router = APIRouter() | |
| def create_session(db: Session = Depends(get_db)): | |
| db_session = DBSession(status="active") | |
| db.add(db_session) | |
| db.commit() | |
| db.refresh(db_session) | |
| return db_session | |
| def get_session(session_id: int, db: Session = Depends(get_db)): | |
| session = db.query(DBSession).filter(DBSession.id == session_id).first() | |
| if not session: | |
| raise HTTPException(status_code=404, detail="Session not found") | |
| intake = db.query(PatientIntake).filter(PatientIntake.session_id == session_id).first() | |
| return { | |
| "id": session.id, | |
| "status": session.status, | |
| "intake": intake.__dict__ if intake else None, | |
| "turns": [{"speaker": t.speaker, "transcript": t.transcript} for t in session.turns] | |
| } | |