imperialwool's picture
Upload 5 files
dfae564
raw
history blame
1.24 kB
# import main things
from fastapi import Depends, FastAPI, Body
from fastapi.responses import JSONResponse, HTMLResponse
from uvicorn import run
from utils import predict
from fastapi_limiter import FastAPILimiter
from fastapi_limiter.depends import RateLimiter
import redis.asyncio as aioredis
# initing things
app = FastAPI()
@app.on_event("startup")
async def startup():
redis = aioredis.from_url("redis://localhost", encoding="utf-8", decode_responses=True)
await FastAPILimiter.init(redis)
@app.get("/", dependencies=[Depends(RateLimiter(times=5, minutes=1))])
@app.post("/", dependencies=[Depends(RateLimiter(times=5, minutes=1))])
async def root():
return JSONResponse({"detail":"Not Found"}, 404)
@app.get("/amino-captcha-ocr/api/v1/autoregister/version")
async def v(): return {"v": 4, "l": ""}
@app.get("/amino-captcha-ocr/api/v1/predict", dependencies=[Depends(RateLimiter(times=5, minutes=1))])
async def resolveGet():
return JSONResponse({"detail":"Use POST instead GET"}, 400)
@app.post("/amino-captcha-ocr/api/v1/predict", dependencies=[Depends(RateLimiter(times=5, minutes=1))])
async def resolvePost(data = Body()):
return await predict(data["url"])
run(app, host="0.0.0.0", port=80)