dev2004v/ai-content-detector
0
1from fastapi import FastAPI2from pydantic import BaseModel3from fastapi.middleware.cors import CORSMiddleware4from model import predict_text5 6app = FastAPI(title="AI Content Detector API")7 8app.add_middleware(9 CORSMiddleware,10 allow_origins=["chrome-extension://*"], # Allow all Chrome extensions11 allow_credentials=True,12 allow_methods=["*"], # Allow all HTTP methods (GET, POST, etc.)13 allow_headers=["*"], # Allow all headers14)15 16class TextInput(BaseModel):17 text: str18 19@app.get("/")20async def home():21 return {"message": "Welcome to the AI Content Detector API"} 22 23@app.post("/predict/")24async def predict(input_data: TextInput):25 """Receive text and return AI detection result."""26 result = predict_text(input_data.text)27 28 print(f"RESULT\n{result}")29 30 return {31 "generated": result["generated"], 32 "probability": result["probability"]33 }34 35# if __name__ == "__main__":36# import uvicorn37# uvicorn.run(app, host="0.0.0.0", port=8000)38 