Download app/api/serializers.py from nvikou/Sheetly: direct link, hf CLI and curl.
- Browser
- Download file 1.25 kB
-
https://huggingface.co/spaces/nvikou/Sheetly/resolve/main/app/api/serializers.py
- Command line
-
hf download hf://spaces/nvikou/Sheetly/app/api/serializers.py
-
curl -L -o serializers.py https://huggingface.co/spaces/nvikou/Sheetly/resolve/main/app/api/serializers.py
1.25 kB
| """API response serializers.""" | |
| from __future__ import annotations | |
| from app.models import Batch, Document | |
| from app.schemas import BatchOut, DocumentOut | |
| def document_out(doc: Document) -> DocumentOut: | |
| """Map ORM document to API schema.""" | |
| return DocumentOut( | |
| id=doc.id, | |
| batch_id=doc.batch_id, | |
| filename=doc.filename, | |
| doc_type=doc.doc_type, | |
| status=doc.status, | |
| language=doc.language or "", | |
| extracted=doc.extracted, | |
| confidence=doc.confidence, | |
| issues=doc.issues or [], | |
| is_duplicate=bool(doc.is_duplicate), | |
| duplicate_of=doc.duplicate_of, | |
| error=doc.error, | |
| avg_confidence=doc.avg_confidence, | |
| created_at=doc.created_at, | |
| updated_at=doc.updated_at, | |
| ) | |
| def batch_out(batch: Batch) -> BatchOut: | |
| """Serialize batch with progress percent.""" | |
| progress = 0.0 | |
| if batch.total > 0: | |
| progress = round(100.0 * batch.processed / batch.total, 1) | |
| return BatchOut( | |
| id=batch.id, | |
| status=batch.status, | |
| total=batch.total, | |
| processed=batch.processed, | |
| failed=batch.failed, | |
| progress=progress, | |
| created_at=batch.created_at, | |
| finished_at=batch.finished_at, | |
| ) | |