Spaces:
Runtime error
Runtime error
File size: 3,330 Bytes
4fc93b8 27e6062 4fc93b8 8e30b6a 4fc93b8 8e30b6a 27e6062 8e30b6a 4fc93b8 8e30b6a 27e6062 8e30b6a 27e6062 8e30b6a 27e6062 4fc93b8 8e30b6a 4fc93b8 8e30b6a 4fc93b8 8e30b6a 4fc93b8 8e30b6a 4fc93b8 8e30b6a 4fc93b8 dcb5a1a 8e30b6a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | from pydantic import BaseModel, HttpUrl, Field
from typing import Union, Literal, Optional
class TextAnalysisRequest(BaseModel):
content_type: Literal["text"]
text: str = Field(..., description="Text content to analyze for deepfake detection")
class Config:
json_schema_extra = {
"example": {
"content_type": "text",
"text": "Some text that might be AI-generated"
}
}
class ImageAnalysisRequest(BaseModel):
content_type: Literal["image"]
image_url: HttpUrl = Field(..., description="URL of the image to analyze")
class Config:
json_schema_extra = {
"example": {
"content_type": "image",
"image_url": "https://example.com/image.jpg"
}
}
class VideoAnalysisRequest(BaseModel):
content_type: Literal["video"]
video_url: HttpUrl = Field(..., description="URL of the video to analyze")
class Config:
json_schema_extra = {
"example": {
"content_type": "video",
"video_url": "https://example.com/video.mp4"
}
}
class FileAnalysisRequest(BaseModel):
content_type: Literal["file"]
file_url: HttpUrl = Field(..., description="URL of the file to analyze")
class Config:
json_schema_extra = {
"example": {
"content_type": "file",
"file_url": "https://example.com/video.mp4"
}
}
AnalysisRequest = Union[
TextAnalysisRequest,
ImageAnalysisRequest,
VideoAnalysisRequest,
FileAnalysisRequest,
]
class AnalysisResponse(BaseModel):
is_deepfake: bool = Field(..., description="Whether the content is detected as a deepfake")
confidence: float = Field(..., ge=0.0, le=1.0, description="Confidence score between 0.0 and 1.0")
analysis_time: float = Field(..., description="Time taken for analysis in seconds")
model_used: str = Field(..., description="The detector model that was used")
content_type: str = Field(..., description="Type of content analyzed (text/image/video/file)")
class Config:
json_schema_extra = {
"example": {
"is_deepfake": True,
"confidence": 0.847,
"analysis_time": 1.234,
"model_used": "mock",
"content_type": "image"
}
}
class ErrorResponse(BaseModel):
error: str = Field(..., description="Error message")
status_code: int = Field(..., description="HTTP status code")
details: Optional[str] = Field(None, description="Additional error details")
class Config:
json_schema_extra = {
"example": {
"error": "Invalid URL format",
"status_code": 400,
"details": "The provided URL is not valid"
}
}
class HealthResponse(BaseModel):
status: str = Field(..., description="Service status")
service: str = Field(..., description="Service name")
version: str = Field(..., description="Service version")
available_models: dict = Field(..., description="Available detector models per content type")
supported_types: list = Field(..., description="Supported content types")
|