Files changed (1) hide show
  1. app.py +26 -40
app.py CHANGED
@@ -1,40 +1,26 @@
1
- from fastapi import FastAPI
2
- from fastapi.responses import HTMLResponse
3
- from fastapi.staticfiles import StaticFiles
4
- from fastapi.templating import Jinja2Templates
5
- from fastapi import Request
6
- import uvicorn
7
-
8
- app = FastAPI()
9
-
10
- # Mount static files
11
- app.mount("/static", StaticFiles(directory="static"), name="static")
12
-
13
- templates = Jinja2Templates(directory="templates")
14
-
15
- # Frontend route
16
- @app.get("/", response_class=HTMLResponse)
17
- async def home(request: Request):
18
- return templates.TemplateResponse("index.html", {"request": request})
19
-
20
- # Your moderation endpoint (example)
21
- @app.post("/moderate")
22
- async def moderate(data: dict):
23
- text = data.get("text", "")
24
-
25
- # 🔥 Replace with your real model logic
26
- return {
27
- "decision": "flag",
28
- "confidence": 0.85,
29
- "explanation": "Potentially harmful content detected",
30
- "ai_scores": {
31
- "toxicity": 0.8,
32
- "insult": 0.6,
33
- "threat": 0.7,
34
- "obscene": 0.5
35
- }
36
- }
37
-
38
- # Run locally
39
- if __name__ == "__main__":
40
- uvicorn.run(app, host="0.0.0.0", port=7860)
 
1
+ from fastapi import FastAPI
2
+ from fastapi.staticfiles import StaticFiles
3
+ from fastapi.responses import FileResponse
4
+ import os
5
+
6
+ app = FastAPI()
7
+
8
+ app.mount("/static", StaticFiles(directory="static"), name="static")
9
+
10
+ @app.get("/")
11
+ async def home():
12
+ return FileResponse(os.path.join("templates", "index.html"))
13
+
14
+ @app.post("/moderate")
15
+ async def moderate(data: dict):
16
+ return {
17
+ "decision": "flag",
18
+ "confidence": 0.85,
19
+ "explanation": "Potentially harmful content detected",
20
+ "ai_scores": {
21
+ "toxicity": 0.8,
22
+ "insult": 0.6,
23
+ "threat": 0.7,
24
+ "obscene": 0.5
25
+ }
26
+ }