ai-content-detector / server.py
dev2004v's picture
Update server.py
dbc3c40 verified
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)