Spaces:
Sleeping
Sleeping
Update server.py
Browse files
server.py
CHANGED
|
@@ -1,33 +1,37 @@
|
|
| 1 |
-
from fastapi import FastAPI
|
| 2 |
-
from pydantic import BaseModel
|
| 3 |
-
from fastapi.middleware.cors import CORSMiddleware
|
| 4 |
-
from api.model import predict_text
|
| 5 |
-
|
| 6 |
-
app = FastAPI(title="AI Content Detector API")
|
| 7 |
-
|
| 8 |
-
app.add_middleware(
|
| 9 |
-
CORSMiddleware,
|
| 10 |
-
allow_origins=["chrome-extension://*"], # Allow all Chrome extensions
|
| 11 |
-
allow_credentials=True,
|
| 12 |
-
allow_methods=["*"], # Allow all HTTP methods (GET, POST, etc.)
|
| 13 |
-
allow_headers=["*"], # Allow all headers
|
| 14 |
-
)
|
| 15 |
-
|
| 16 |
-
class TextInput(BaseModel):
|
| 17 |
-
text: str
|
| 18 |
-
|
| 19 |
-
@app.
|
| 20 |
-
async def
|
| 21 |
-
"""
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI
|
| 2 |
+
from pydantic import BaseModel
|
| 3 |
+
from fastapi.middleware.cors import CORSMiddleware
|
| 4 |
+
from api.model import predict_text
|
| 5 |
+
|
| 6 |
+
app = FastAPI(title="AI Content Detector API")
|
| 7 |
+
|
| 8 |
+
app.add_middleware(
|
| 9 |
+
CORSMiddleware,
|
| 10 |
+
allow_origins=["chrome-extension://*"], # Allow all Chrome extensions
|
| 11 |
+
allow_credentials=True,
|
| 12 |
+
allow_methods=["*"], # Allow all HTTP methods (GET, POST, etc.)
|
| 13 |
+
allow_headers=["*"], # Allow all headers
|
| 14 |
+
)
|
| 15 |
+
|
| 16 |
+
class TextInput(BaseModel):
|
| 17 |
+
text: str
|
| 18 |
+
|
| 19 |
+
@app.get("/")
|
| 20 |
+
async def home():
|
| 21 |
+
return {"message": "Welcome to the AI Content Detector API"}
|
| 22 |
+
|
| 23 |
+
@app.post("/predict/")
|
| 24 |
+
async 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 uvicorn
|
| 37 |
+
# uvicorn.run(app, host="0.0.0.0", port=8000)
|