Spaces:
Sleeping
Sleeping
Download features/text_classifier/routes.py from can-org/Testing-AI-Contain: direct link, hf CLI and curl.
- Browser
- Download file 1.66 kB
-
https://huggingface.co/spaces/can-org/Testing-AI-Contain/resolve/main/features/text_classifier/routes.py
- Command line
-
hf download hf://spaces/can-org/Testing-AI-Contain/features/text_classifier/routes.py
-
curl -L -o routes.py https://huggingface.co/spaces/can-org/Testing-AI-Contain/resolve/main/features/text_classifier/routes.py
1.66 kB
| from fastapi import APIRouter, Depends, HTTPException, UploadFile, File, Request | |
| from fastapi.security import HTTPBearer | |
| from pydantic import BaseModel | |
| from slowapi.util import get_remote_address | |
| from slowapi import Limiter | |
| from slowapi.errors import RateLimitExceeded | |
| from config import ACCESS_RATE | |
| from .controller import ( | |
| handle_text_analysis, | |
| handle_file_upload, | |
| handle_sentence_level_analysis, | |
| handle_file_sentence, | |
| verify_token | |
| ) | |
| limiter = Limiter(key_func=get_remote_address) | |
| router = APIRouter() | |
| security = HTTPBearer() | |
| class TextInput(BaseModel): | |
| text: str | |
| async def analyze(request: Request, data: TextInput, token: str = Depends(verify_token)): | |
| return await handle_text_analysis(data.text) | |
| async def upload_file(request: Request, file: UploadFile = File(...), token: str = Depends(verify_token)): | |
| return await handle_file_upload(file) | |
| async def analyze_sentences(request: Request, data: TextInput, token: str = Depends(verify_token)): | |
| if not data.text: | |
| raise HTTPException(status_code=400, detail="Missing 'text' in request body") | |
| return await handle_sentence_level_analysis(data.text) | |
| async def analyze_sentence_file(request: Request, file: UploadFile = File(...), token: str = Depends(verify_token)): | |
| return await handle_file_sentence(file) | |
| def health(request: Request): | |
| return {"status": "ok"} | |