| from fastapi import FastAPI |
| from fastapi.middleware.cors import CORSMiddleware |
| from pydantic import BaseModel |
|
|
| from ai_score import PTTScorer |
|
|
| app = FastAPI() |
|
|
| app.add_middleware( |
| CORSMiddleware, |
| allow_origins=["*"], |
| allow_credentials=False, |
| allow_methods=["*"], |
| allow_headers=["*"], |
| ) |
|
|
| class Req(BaseModel): |
| text: str |
|
|
| |
| scorer = PTTScorer() |
|
|
| @app.post("/detect") |
| def detect(req: Req): |
| out = scorer.score(req.text) |
|
|
| |
| label_map = { |
| "human_like": "Human-like", |
| "maybe_human_like": "Mixed", |
| "ai_slop_like": "AI-like", |
| "unknown": "Unknown", |
| } |
|
|
| return { |
| "label": label_map.get(out["label"], out["label"]), |
| "cleanowl_label": out["label"], |
| "score": out.get("score", 0), |
| "raw": out.get("raw", 0), |
| "mean": out.get("mean", 0), |
| "var": out.get("var", 0), |
| "peak": out.get("peak", 0), |
| "len_var": out.get("len_var", 0), |
| "continuity": out.get("continuity", 0), |
| "punct_ratio": out.get("punct_ratio", 0), |
| "formal_punct_ratio": out.get("formal_punct_ratio", 0), |
| "tokens": out.get("tokens", [])[:30], |
| } |