Spaces:
Sleeping
Sleeping
Create schemas.py
Browse files- schemas.py +129 -0
schemas.py
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Pydantic schemas for API validation
|
| 3 |
+
"""
|
| 4 |
+
from pydantic import BaseModel, Field
|
| 5 |
+
from typing import Optional, List
|
| 6 |
+
from datetime import datetime
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
class HFConfigUpdate(BaseModel):
|
| 10 |
+
"""Schema for updating HF configuration"""
|
| 11 |
+
hf_token: Optional[str] = None
|
| 12 |
+
source_all_repo: Optional[str] = None
|
| 13 |
+
source_ato_repo: Optional[str] = None
|
| 14 |
+
target_repo: Optional[str] = None
|
| 15 |
+
upload_batch_size: Optional[int] = None
|
| 16 |
+
max_uploads_per_hour: Optional[int] = None
|
| 17 |
+
|
| 18 |
+
class Config:
|
| 19 |
+
from_attributes = True
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
class HFConfigResponse(BaseModel):
|
| 23 |
+
"""Schema for HF configuration response"""
|
| 24 |
+
id: int
|
| 25 |
+
hf_token: Optional[str] = None
|
| 26 |
+
source_all_repo: str
|
| 27 |
+
source_ato_repo: str
|
| 28 |
+
target_repo: str
|
| 29 |
+
upload_batch_size: int
|
| 30 |
+
max_uploads_per_hour: int
|
| 31 |
+
created_at: datetime
|
| 32 |
+
updated_at: datetime
|
| 33 |
+
|
| 34 |
+
class Config:
|
| 35 |
+
from_attributes = True
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
class UploadQueueItem(BaseModel):
|
| 39 |
+
"""Schema for upload queue item"""
|
| 40 |
+
id: int
|
| 41 |
+
file_name: str
|
| 42 |
+
file_path: str
|
| 43 |
+
file_size: int
|
| 44 |
+
status: str
|
| 45 |
+
uploaded_at: Optional[datetime] = None
|
| 46 |
+
failure_reason: Optional[str] = None
|
| 47 |
+
retry_count: int
|
| 48 |
+
max_retries: int
|
| 49 |
+
created_at: datetime
|
| 50 |
+
updated_at: datetime
|
| 51 |
+
|
| 52 |
+
class Config:
|
| 53 |
+
from_attributes = True
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
class UploadQueueStats(BaseModel):
|
| 57 |
+
"""Schema for upload queue statistics"""
|
| 58 |
+
pending: int
|
| 59 |
+
uploading: int
|
| 60 |
+
completed: int
|
| 61 |
+
failed: int
|
| 62 |
+
total: int
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
class ProcessingStateResponse(BaseModel):
|
| 66 |
+
"""Schema for processing state response"""
|
| 67 |
+
id: int
|
| 68 |
+
status: str
|
| 69 |
+
total_files: int
|
| 70 |
+
processed_files: int
|
| 71 |
+
matched_pairs: int
|
| 72 |
+
error_message: Optional[str] = None
|
| 73 |
+
started_at: Optional[datetime] = None
|
| 74 |
+
completed_at: Optional[datetime] = None
|
| 75 |
+
created_at: datetime
|
| 76 |
+
updated_at: datetime
|
| 77 |
+
|
| 78 |
+
class Config:
|
| 79 |
+
from_attributes = True
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
class ProcessRequest(BaseModel):
|
| 83 |
+
"""Schema for process request"""
|
| 84 |
+
max_files: int = Field(default=0, description="0 means process all files")
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
class UploadRequest(BaseModel):
|
| 88 |
+
"""Schema for upload request"""
|
| 89 |
+
file_ids: List[int] = Field(description="List of upload queue item IDs to upload")
|
| 90 |
+
batch_size: int = Field(default=10, description="Number of files per batch")
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
class FilePreviewRequest(BaseModel):
|
| 94 |
+
"""Schema for file preview request"""
|
| 95 |
+
filename: str
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
class FilePreviewResponse(BaseModel):
|
| 99 |
+
"""Schema for file preview response"""
|
| 100 |
+
filename: str
|
| 101 |
+
size: int
|
| 102 |
+
content: dict
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
class RateLimitStatus(BaseModel):
|
| 106 |
+
"""Schema for rate limit status"""
|
| 107 |
+
can_upload: bool
|
| 108 |
+
remaining_uploads: int
|
| 109 |
+
resume_time: Optional[datetime] = None
|
| 110 |
+
|
| 111 |
+
|
| 112 |
+
class UploadStatus(BaseModel):
|
| 113 |
+
"""Schema for upload status"""
|
| 114 |
+
rate_limit: RateLimitStatus
|
| 115 |
+
config: Optional[HFConfigResponse] = None
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
class ErrorLogResponse(BaseModel):
|
| 119 |
+
"""Schema for error log response"""
|
| 120 |
+
id: int
|
| 121 |
+
file_name: str
|
| 122 |
+
error_code: Optional[str] = None
|
| 123 |
+
error_message: Optional[str] = None
|
| 124 |
+
status_code: Optional[int] = None
|
| 125 |
+
retryable: bool
|
| 126 |
+
created_at: datetime
|
| 127 |
+
|
| 128 |
+
class Config:
|
| 129 |
+
from_attributes = True
|