Spaces:
Sleeping
Sleeping
| 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 | |
| async def home(): | |
| return {"message": "Welcome to the AI Content Detector API"} | |
| 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) | |