Spaces:
Runtime error
Runtime error
Download app/api/v1/endpoints/moderation.py from AsyncCoder-10/my-moderation-api: direct link, hf CLI and curl.
- Browser
- Download file 661 Bytes
-
https://huggingface.co/spaces/AsyncCoder-10/my-moderation-api/resolve/main/app/api/v1/endpoints/moderation.py
- Command line
-
hf download hf://spaces/AsyncCoder-10/my-moderation-api/app/api/v1/endpoints/moderation.py
-
curl -L -o moderation.py https://huggingface.co/spaces/AsyncCoder-10/my-moderation-api/resolve/main/app/api/v1/endpoints/moderation.py
661 Bytes
| from fastapi import APIRouter, HTTPException | |
| from app.schemas.moderation import ModerationRequest, ModerationResponse | |
| from app.services.moderation_service import moderation_service | |
| router = APIRouter() | |
| async def moderate_text(request: ModerationRequest): | |
| """ | |
| Check a piece of text for toxicity. If flagged, returns 8 AI-generated safe alternatives. | |
| """ | |
| try: | |
| result = moderation_service.get_moderation_scores(request.text) | |
| return ModerationResponse(**result) | |
| except RuntimeError as e: | |
| raise HTTPException(status_code=500, detail=str(e)) | |