File size: 1,000 Bytes
0a46bbe
 
 
dbc3c40
0a46bbe
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from fastapi import FastAPI
from pydantic import BaseModel
from fastapi.middleware.cors import CORSMiddleware
from model import predict_text

app = FastAPI(title="AI Content Detector API")

app.add_middleware(
    CORSMiddleware,
    allow_origins=["chrome-extension://*"],  # Allow all Chrome extensions
    allow_credentials=True,
    allow_methods=["*"],  # Allow all HTTP methods (GET, POST, etc.)
    allow_headers=["*"],  # Allow all headers
)

class TextInput(BaseModel):
    text: str

@app.get("/")
async def home():
    return {"message": "Welcome to the AI Content Detector API"}    

@app.post("/predict/")
async def predict(input_data: TextInput):
    """Receive text and return AI detection result."""
    result = predict_text(input_data.text)

    print(f"RESULT\n{result}")

    return {
        "generated": result["generated"], 
        "probability": result["probability"]
    }

# if __name__ == "__main__":
#     import uvicorn
#     uvicorn.run(app, host="0.0.0.0", port=8000)