Spaces:
Sleeping
Sleeping
| """ | |
| Pydantic models for request/response validation | |
| """ | |
| from pydantic import BaseModel, Field | |
| from typing import List, Dict, Optional | |
| class TextRequest(BaseModel): | |
| """Request model for text-only analysis""" | |
| text: str = Field(..., min_length=10, description="Radiology report text") | |
| class Config: | |
| json_schema_extra = { | |
| "example": { | |
| "text": "FINDINGS: The cardiac silhouette is within normal limits. The lungs are clear. No pleural effusion or pneumothorax." | |
| } | |
| } | |
| class Entity(BaseModel): | |
| """Individual entity detected by NER""" | |
| text: str | |
| label: str | |
| start: int | |
| end: int | |
| confidence: float = 0.99 | |
| class StructuredReport(BaseModel): | |
| """Structured representation of report findings""" | |
| anatomy: List[str] | |
| all_observations: List[str] | |
| positive_findings: List[str] | |
| negative_findings: List[str] | |
| critical_findings: List[str] | |
| class Summary(BaseModel): | |
| """Summary statistics of the analysis""" | |
| total_entities: int | |
| anatomy_count: int | |
| observations_count: int | |
| has_critical_findings: bool | |
| has_abnormalities: bool | |
| class ImageData(BaseModel): | |
| """Extracted image from PDF""" | |
| page: int | |
| format: str | |
| width: int | |
| height: int | |
| data: str # base64 encoded | |
| class AnalysisResponse(BaseModel): | |
| """Complete analysis response""" | |
| status: str | |
| processing_time: float | |
| input_type: str | |
| ocr_used: bool | |
| ocr_engine: Optional[str] = None | |
| raw_text: str | |
| text_length: int | |
| entities: List[Entity] | |
| structured_report: StructuredReport | |
| summary: Summary | |
| recommendations: List[str] | |
| images: Optional[List[ImageData]] = None | |
| class EncryptedRequest(BaseModel): | |
| """Encrypted and compressed file request""" | |
| ciphertext: str | |
| nonce: str | |
| class Config: | |
| json_schema_extra = { | |
| "example": { | |
| "ciphertext": "mJXnK8p9VGhpN...", | |
| "nonce": "Y2FzZGFzZGFzZA==" | |
| } | |
| } | |
| class EncryptedResponse(BaseModel): | |
| """Encrypted response""" | |
| ciphertext: str | |
| nonce: str | |
| status: str = "success" | |