Files changed (1) hide show
  1. app.py +42 -39
app.py CHANGED
@@ -1,40 +1,43 @@
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.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
+ from fastapi.responses import FileResponse
17
+ import os
18
+
19
+ @app.get("/")
20
+ async def home():
21
+ return FileResponse(os.path.join("templates", "index.html"))
22
+
23
+ # Your moderation endpoint (example)
24
+ @app.post("/moderate")
25
+ async def moderate(data: dict):
26
+ text = data.get("text", "")
27
+
28
+ # 🔥 Replace with your real model logic
29
+ return {
30
+ "decision": "flag",
31
+ "confidence": 0.85,
32
+ "explanation": "Potentially harmful content detected",
33
+ "ai_scores": {
34
+ "toxicity": 0.8,
35
+ "insult": 0.6,
36
+ "threat": 0.7,
37
+ "obscene": 0.5
38
+ }
39
+ }
40
+
41
+ # Run locally
42
+ if __name__ == "__main__":
43
  uvicorn.run(app, host="0.0.0.0", port=7860)