Spaces:
Sleeping
Sleeping
first model fixed
Browse files- backend/app/api/routes.py +12 -31
- backend/app/models/schemas.py +5 -13
- backend/requirements.txt +2 -0
backend/app/api/routes.py
CHANGED
|
@@ -86,14 +86,13 @@ async def analyze(request: AnalysisRequest) -> AnalysisResponse:
|
|
| 86 |
detail="Text content must be at least 10 characters"
|
| 87 |
)
|
| 88 |
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
if model not in AVAILABLE_MODELS["text"]:
|
| 92 |
raise HTTPException(
|
| 93 |
status_code=400,
|
| 94 |
-
detail=
|
| 95 |
)
|
| 96 |
|
|
|
|
| 97 |
logger.info(f"Received text analysis request, length: {len(request.text)} chars, model: {model}")
|
| 98 |
|
| 99 |
try:
|
|
@@ -116,20 +115,14 @@ async def analyze(request: AnalysisRequest) -> AnalysisResponse:
|
|
| 116 |
|
| 117 |
elif isinstance(request, ImageAnalysisRequest):
|
| 118 |
content_type = "image"
|
| 119 |
-
model = request.model
|
| 120 |
|
| 121 |
-
if not
|
| 122 |
raise HTTPException(
|
| 123 |
status_code=400,
|
| 124 |
-
detail=
|
| 125 |
-
)
|
| 126 |
-
|
| 127 |
-
if model not in AVAILABLE_MODELS["image"]:
|
| 128 |
-
raise HTTPException(
|
| 129 |
-
status_code=400,
|
| 130 |
-
detail=f"Model '{model}' is not available for image analysis. Available models: {AVAILABLE_MODELS['image']}"
|
| 131 |
)
|
| 132 |
|
|
|
|
| 133 |
logger.info(f"Received image analysis request for URL: {request.image_url}, model: {model}")
|
| 134 |
|
| 135 |
try:
|
|
@@ -160,20 +153,14 @@ async def analyze(request: AnalysisRequest) -> AnalysisResponse:
|
|
| 160 |
|
| 161 |
elif isinstance(request, VideoAnalysisRequest):
|
| 162 |
content_type = "video"
|
| 163 |
-
model = request.model
|
| 164 |
|
| 165 |
-
if not
|
| 166 |
raise HTTPException(
|
| 167 |
status_code=400,
|
| 168 |
-
detail=
|
| 169 |
-
)
|
| 170 |
-
|
| 171 |
-
if model not in AVAILABLE_MODELS["video"]:
|
| 172 |
-
raise HTTPException(
|
| 173 |
-
status_code=400,
|
| 174 |
-
detail=f"Model '{model}' is not available for video analysis. Available models: {AVAILABLE_MODELS['video']}"
|
| 175 |
)
|
| 176 |
|
|
|
|
| 177 |
logger.info(f"Received video analysis request for URL: {request.video_url}, model: {model}")
|
| 178 |
|
| 179 |
try:
|
|
@@ -204,20 +191,14 @@ async def analyze(request: AnalysisRequest) -> AnalysisResponse:
|
|
| 204 |
|
| 205 |
elif isinstance(request, FileAnalysisRequest):
|
| 206 |
content_type = "file"
|
| 207 |
-
model = request.model
|
| 208 |
-
|
| 209 |
-
if not model:
|
| 210 |
-
raise HTTPException(
|
| 211 |
-
status_code=400,
|
| 212 |
-
detail=f"No model available for file analysis. Available models: {AVAILABLE_MODELS['file']}"
|
| 213 |
-
)
|
| 214 |
|
| 215 |
-
if
|
| 216 |
raise HTTPException(
|
| 217 |
status_code=400,
|
| 218 |
-
detail=
|
| 219 |
)
|
| 220 |
|
|
|
|
| 221 |
logger.info(f"Received file analysis request for URL: {request.file_url}, model: {model}")
|
| 222 |
|
| 223 |
try:
|
|
|
|
| 86 |
detail="Text content must be at least 10 characters"
|
| 87 |
)
|
| 88 |
|
| 89 |
+
if not AVAILABLE_MODELS["text"]:
|
|
|
|
|
|
|
| 90 |
raise HTTPException(
|
| 91 |
status_code=400,
|
| 92 |
+
detail="No model available for text analysis"
|
| 93 |
)
|
| 94 |
|
| 95 |
+
model = AVAILABLE_MODELS["text"][0]
|
| 96 |
logger.info(f"Received text analysis request, length: {len(request.text)} chars, model: {model}")
|
| 97 |
|
| 98 |
try:
|
|
|
|
| 115 |
|
| 116 |
elif isinstance(request, ImageAnalysisRequest):
|
| 117 |
content_type = "image"
|
|
|
|
| 118 |
|
| 119 |
+
if not AVAILABLE_MODELS["image"]:
|
| 120 |
raise HTTPException(
|
| 121 |
status_code=400,
|
| 122 |
+
detail="No model available for image analysis"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
)
|
| 124 |
|
| 125 |
+
model = AVAILABLE_MODELS["image"][0]
|
| 126 |
logger.info(f"Received image analysis request for URL: {request.image_url}, model: {model}")
|
| 127 |
|
| 128 |
try:
|
|
|
|
| 153 |
|
| 154 |
elif isinstance(request, VideoAnalysisRequest):
|
| 155 |
content_type = "video"
|
|
|
|
| 156 |
|
| 157 |
+
if not AVAILABLE_MODELS["video"]:
|
| 158 |
raise HTTPException(
|
| 159 |
status_code=400,
|
| 160 |
+
detail="No model available for video analysis"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 161 |
)
|
| 162 |
|
| 163 |
+
model = AVAILABLE_MODELS["video"][0]
|
| 164 |
logger.info(f"Received video analysis request for URL: {request.video_url}, model: {model}")
|
| 165 |
|
| 166 |
try:
|
|
|
|
| 191 |
|
| 192 |
elif isinstance(request, FileAnalysisRequest):
|
| 193 |
content_type = "file"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 194 |
|
| 195 |
+
if not AVAILABLE_MODELS["file"]:
|
| 196 |
raise HTTPException(
|
| 197 |
status_code=400,
|
| 198 |
+
detail="No model available for file analysis"
|
| 199 |
)
|
| 200 |
|
| 201 |
+
model = AVAILABLE_MODELS["file"][0]
|
| 202 |
logger.info(f"Received file analysis request for URL: {request.file_url}, model: {model}")
|
| 203 |
|
| 204 |
try:
|
backend/app/models/schemas.py
CHANGED
|
@@ -1,18 +1,16 @@
|
|
| 1 |
from pydantic import BaseModel, HttpUrl, Field
|
| 2 |
-
from typing import
|
| 3 |
|
| 4 |
|
| 5 |
class TextAnalysisRequest(BaseModel):
|
| 6 |
content_type: Literal["text"]
|
| 7 |
text: str = Field(..., description="Text content to analyze for deepfake detection")
|
| 8 |
-
model: Optional[str] = Field(None, description="Detector model to use")
|
| 9 |
|
| 10 |
class Config:
|
| 11 |
json_schema_extra = {
|
| 12 |
"example": {
|
| 13 |
"content_type": "text",
|
| 14 |
-
"text": "Some text that might be AI-generated"
|
| 15 |
-
"model": "mock"
|
| 16 |
}
|
| 17 |
}
|
| 18 |
|
|
@@ -20,14 +18,12 @@ class TextAnalysisRequest(BaseModel):
|
|
| 20 |
class ImageAnalysisRequest(BaseModel):
|
| 21 |
content_type: Literal["image"]
|
| 22 |
image_url: HttpUrl = Field(..., description="URL of the image to analyze")
|
| 23 |
-
model: Optional[str] = Field(None, description="Detector model to use")
|
| 24 |
|
| 25 |
class Config:
|
| 26 |
json_schema_extra = {
|
| 27 |
"example": {
|
| 28 |
"content_type": "image",
|
| 29 |
-
"image_url": "https://example.com/image.jpg"
|
| 30 |
-
"model": "mock"
|
| 31 |
}
|
| 32 |
}
|
| 33 |
|
|
@@ -35,14 +31,12 @@ class ImageAnalysisRequest(BaseModel):
|
|
| 35 |
class VideoAnalysisRequest(BaseModel):
|
| 36 |
content_type: Literal["video"]
|
| 37 |
video_url: HttpUrl = Field(..., description="URL of the video to analyze")
|
| 38 |
-
model: Optional[str] = Field(None, description="Detector model to use")
|
| 39 |
|
| 40 |
class Config:
|
| 41 |
json_schema_extra = {
|
| 42 |
"example": {
|
| 43 |
"content_type": "video",
|
| 44 |
-
"video_url": "https://example.com/video.mp4"
|
| 45 |
-
"model": "mock"
|
| 46 |
}
|
| 47 |
}
|
| 48 |
|
|
@@ -50,14 +44,12 @@ class VideoAnalysisRequest(BaseModel):
|
|
| 50 |
class FileAnalysisRequest(BaseModel):
|
| 51 |
content_type: Literal["file"]
|
| 52 |
file_url: HttpUrl = Field(..., description="URL of the file to analyze")
|
| 53 |
-
model: Optional[str] = Field(None, description="Detector model to use")
|
| 54 |
|
| 55 |
class Config:
|
| 56 |
json_schema_extra = {
|
| 57 |
"example": {
|
| 58 |
"content_type": "file",
|
| 59 |
-
"file_url": "https://example.com/video.mp4"
|
| 60 |
-
"model": "mock"
|
| 61 |
}
|
| 62 |
}
|
| 63 |
|
|
|
|
| 1 |
from pydantic import BaseModel, HttpUrl, Field
|
| 2 |
+
from typing import Union, Literal, Optional
|
| 3 |
|
| 4 |
|
| 5 |
class TextAnalysisRequest(BaseModel):
|
| 6 |
content_type: Literal["text"]
|
| 7 |
text: str = Field(..., description="Text content to analyze for deepfake detection")
|
|
|
|
| 8 |
|
| 9 |
class Config:
|
| 10 |
json_schema_extra = {
|
| 11 |
"example": {
|
| 12 |
"content_type": "text",
|
| 13 |
+
"text": "Some text that might be AI-generated"
|
|
|
|
| 14 |
}
|
| 15 |
}
|
| 16 |
|
|
|
|
| 18 |
class ImageAnalysisRequest(BaseModel):
|
| 19 |
content_type: Literal["image"]
|
| 20 |
image_url: HttpUrl = Field(..., description="URL of the image to analyze")
|
|
|
|
| 21 |
|
| 22 |
class Config:
|
| 23 |
json_schema_extra = {
|
| 24 |
"example": {
|
| 25 |
"content_type": "image",
|
| 26 |
+
"image_url": "https://example.com/image.jpg"
|
|
|
|
| 27 |
}
|
| 28 |
}
|
| 29 |
|
|
|
|
| 31 |
class VideoAnalysisRequest(BaseModel):
|
| 32 |
content_type: Literal["video"]
|
| 33 |
video_url: HttpUrl = Field(..., description="URL of the video to analyze")
|
|
|
|
| 34 |
|
| 35 |
class Config:
|
| 36 |
json_schema_extra = {
|
| 37 |
"example": {
|
| 38 |
"content_type": "video",
|
| 39 |
+
"video_url": "https://example.com/video.mp4"
|
|
|
|
| 40 |
}
|
| 41 |
}
|
| 42 |
|
|
|
|
| 44 |
class FileAnalysisRequest(BaseModel):
|
| 45 |
content_type: Literal["file"]
|
| 46 |
file_url: HttpUrl = Field(..., description="URL of the file to analyze")
|
|
|
|
| 47 |
|
| 48 |
class Config:
|
| 49 |
json_schema_extra = {
|
| 50 |
"example": {
|
| 51 |
"content_type": "file",
|
| 52 |
+
"file_url": "https://example.com/video.mp4"
|
|
|
|
| 53 |
}
|
| 54 |
}
|
| 55 |
|
backend/requirements.txt
CHANGED
|
@@ -7,3 +7,5 @@ python-multipart==0.0.6
|
|
| 7 |
transformers==4.41.2
|
| 8 |
torch==2.3.1
|
| 9 |
numpy==1.26.4
|
|
|
|
|
|
|
|
|
| 7 |
transformers==4.41.2
|
| 8 |
torch==2.3.1
|
| 9 |
numpy==1.26.4
|
| 10 |
+
sentencepiece
|
| 11 |
+
protobuf
|