Spaces:
Running
Running
File size: 879 Bytes
4fee431 |
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 27 28 29 30 |
from slowapi import Limiter
from config import ACCESS_RATE
from .controller import nepali_text_analysis
from .inferencer import classify_text
from fastapi import APIRouter, Request, Depends, HTTPException
from fastapi.security import HTTPBearer
from slowapi import Limiter
from slowapi.util import get_remote_address
from pydantic import BaseModel
router = APIRouter()
limiter = Limiter(key_func=get_remote_address)
security = HTTPBearer()
# Input schema
class TextInput(BaseModel):
text: str
@router.post("/analyse")
@limiter.limit(ACCESS_RATE)
async def analyse(request: Request, data: TextInput, token: str = Depends(security)):
# Token is available as `token.credentials`, add validation if needed
result = classify_text(data.text)
return result
@router.get("/health")
@limiter.limit(ACCESS_RATE)
def health(request: Request):
return {"status": "ok"}
|