Spaces:
Sleeping
Sleeping
Download app.py from deep9933/Toxic-Dector: direct link, hf CLI and curl.
- Browser
- Download file 645 Bytes
-
https://huggingface.co/spaces/deep9933/Toxic-Dector/resolve/main/app.py
- Command line
-
hf download hf://spaces/deep9933/Toxic-Dector/app.py
-
curl -L -o app.py https://huggingface.co/spaces/deep9933/Toxic-Dector/resolve/main/app.py
645 Bytes
| from fastapi import FastAPI | |
| from pydantic import BaseModel | |
| from model import predict | |
| from fastapi.middleware.cors import CORSMiddleware | |
| app = FastAPI(title="Toxic Language Detector") | |
| # ✅ Enable CORS (VERY IMPORTANT for frontend) | |
| app.add_middleware( | |
| CORSMiddleware, | |
| allow_origins=["*"], | |
| allow_credentials=True, | |
| allow_methods=["*"], | |
| allow_headers=["*"], | |
| ) | |
| # ✅ Define request body | |
| class TextRequest(BaseModel): | |
| text: str | |
| def home(): | |
| return {"message": "API is running"} | |
| # ✅ POST API (best practice) | |
| def get_prediction(request: TextRequest): | |
| return predict(request.text) |