File size: 1,115 Bytes
51334f9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
31
32
33
34
35
36
37
38
39
40
from fastapi import FastAPI
from fastapi.responses import HTMLResponse
from fastapi.staticfiles import StaticFiles
from fastapi.templating import Jinja2Templates
from fastapi import Request
import uvicorn

app = FastAPI()

# Mount static files
app.mount("/static", StaticFiles(directory="static"), name="static")

templates = Jinja2Templates(directory="templates")

# Frontend route
@app.get("/", response_class=HTMLResponse)
async def home(request: Request):
    return templates.TemplateResponse("index.html", {"request": request})

# Your moderation endpoint (example)
@app.post("/moderate")
async def moderate(data: dict):
    text = data.get("text", "")

    # 🔥 Replace with your real model logic
    return {
        "decision": "flag",
        "confidence": 0.85,
        "explanation": "Potentially harmful content detected",
        "ai_scores": {
            "toxicity": 0.8,
            "insult": 0.6,
            "threat": 0.7,
            "obscene": 0.5
        }
    }

# Run locally
if __name__ == "__main__":
    uvicorn.run(app, host="0.0.0.0", port=7860)