Spaces:
Sleeping
Sleeping
Merge pull request #12 from Tobkubos/backend-setup
Browse files- backend/app/api/routes.py +7 -1
- backend/app/core/config.py +4 -2
backend/app/api/routes.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
import logging
|
| 2 |
from fastapi import APIRouter, HTTPException, Request, status
|
|
|
|
| 3 |
|
| 4 |
from app.models.schemas import (
|
| 5 |
AnalysisRequest,
|
|
@@ -120,10 +121,15 @@ async def get_discord_guild_config(guild_id: str):
|
|
| 120 |
tags=["Analysis"],
|
| 121 |
summary="Analyze content for deepfake detection",
|
| 122 |
)
|
| 123 |
-
@limiter.limit("1/5seconds")
|
| 124 |
async def analyze(request: Request, payload: AnalysisRequest) -> AnalysisResponse:
|
| 125 |
guild_id = payload.guild_id
|
| 126 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
if isinstance(payload, TextAnalysisRequest):
|
| 128 |
content_type = "text"
|
| 129 |
elif isinstance(payload, ImageAnalysisRequest):
|
|
|
|
| 1 |
import logging
|
| 2 |
from fastapi import APIRouter, HTTPException, Request, status
|
| 3 |
+
from slowapi.errors import RateLimitExceeded
|
| 4 |
|
| 5 |
from app.models.schemas import (
|
| 6 |
AnalysisRequest,
|
|
|
|
| 121 |
tags=["Analysis"],
|
| 122 |
summary="Analyze content for deepfake detection",
|
| 123 |
)
|
|
|
|
| 124 |
async def analyze(request: Request, payload: AnalysisRequest) -> AnalysisResponse:
|
| 125 |
guild_id = payload.guild_id
|
| 126 |
|
| 127 |
+
try:
|
| 128 |
+
limiter.try_increment(f"analyze:{guild_id}", "1/5seconds")
|
| 129 |
+
except RateLimitExceeded:
|
| 130 |
+
raise HTTPException(status_code=429, detail="Rate limit exceeded for this guild")
|
| 131 |
+
|
| 132 |
+
|
| 133 |
if isinstance(payload, TextAnalysisRequest):
|
| 134 |
content_type = "text"
|
| 135 |
elif isinstance(payload, ImageAnalysisRequest):
|
backend/app/core/config.py
CHANGED
|
@@ -30,8 +30,10 @@ class Settings:
|
|
| 30 |
|
| 31 |
AVAILABLE_MODELS = {
|
| 32 |
"text": ["yaya36095/xlm-roberta-text-detector",
|
| 33 |
-
"almanach/xlmr-chatgptdetect-noisy"
|
| 34 |
-
|
|
|
|
|
|
|
| 35 |
}
|
| 36 |
|
| 37 |
MAX_CONTENT_SIZES = {
|
|
|
|
| 30 |
|
| 31 |
AVAILABLE_MODELS = {
|
| 32 |
"text": ["yaya36095/xlm-roberta-text-detector",
|
| 33 |
+
"almanach/xlmr-chatgptdetect-noisy",
|
| 34 |
+
"bibbbu/multilingual-ai-human-detector_xlm-roberta-base"],
|
| 35 |
+
"image": ["capcheck/ai-image-detection",
|
| 36 |
+
"Hemg/Deepfake-image"],
|
| 37 |
}
|
| 38 |
|
| 39 |
MAX_CONTENT_SIZES = {
|