Spaces:
Running
Running
from slowapi import Limiter | |
from config import ACCESS_RATE | |
from fastapi import APIRouter, File, Request, Depends, HTTPException, UploadFile | |
from fastapi.security import HTTPBearer | |
from slowapi import Limiter | |
from slowapi.util import get_remote_address | |
from io import BytesIO | |
from .controller import process_image_ela , verify_token,process_fft_image, process_meta_image | |
import requests | |
router = APIRouter() | |
limiter = Limiter(key_func=get_remote_address) | |
security = HTTPBearer() | |
async def detect_ela(request:Request,file: UploadFile = File(...), quality: int = 90 ,token: str = Depends(verify_token)): | |
# Check file extension | |
allowed_types = ["image/jpeg", "image/png"] | |
if file.content_type not in allowed_types: | |
raise HTTPException( | |
status_code=400, | |
detail="Unsupported file type. Only JPEG and PNG images are allowed." | |
) | |
content = await file.read() | |
result = await process_image_ela(content, quality) | |
return result | |
async def detect_fft(request:Request,file:UploadFile =File(...),threshold:float=0.95,token:str=Depends(verify_token)): | |
if file.content_type not in ["image/jpeg", "image/png"]: | |
raise HTTPException(status_code=400, detail="Unsupported image type.") | |
content = await file.read() | |
result = await process_fft_image(content,threshold) | |
return result | |
async def detect_meta(request:Request,file:UploadFile=File(...),token:str=Depends(verify_token)): | |
if file.content_type not in ["image/jpeg", "image/png"]: | |
raise HTTPException(status_code=400, detail="Unsupported image type.") | |
content = await file.read() | |
result = await process_meta_image(content) | |
return result | |
def heath(request:Request): | |
return {"status":"ok"} | |