Spaces:
Build error
Build error
File size: 889 Bytes
36a599e 2ad48f3 36a599e 2ad48f3 36a599e 2ad48f3 36a599e |
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 |
from fastapi import FastAPI, File, UploadFile, Request
from slowapi import Limiter, _rate_limit_exceeded_handler
from slowapi.util import get_remote_address
from slowapi.errors import RateLimitExceeded
from fastapi.responses import JSONResponse
app = FastAPI()
limiter = Limiter(key_func=get_remote_address)
app.state.limiter = limiter
app.add_exception_handler(RateLimitExceeded, _rate_limit_exceeded_handler)
@app.post("/process")
@limiter.limit("5/minute")
async def process_image(request: Request, file: UploadFile = File(...)):
try:
contents = await file.read()
# Your processing logic here
return JSONResponse(
status_code=200,
content={"message": "Success", "filename": file.filename}
)
except Exception as e:
return JSONResponse(
status_code=500,
content={"error": str(e)}
) |