dev2004v commited on
Commit
0a46bbe
·
verified ·
1 Parent(s): 1747402

Update server.py

Browse files
Files changed (1) hide show
  1. server.py +37 -33
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.post("/predict/")
20
- async def predict(input_data: TextInput):
21
- """Receive text and return AI detection result."""
22
- result = predict_text(input_data.text)
23
-
24
- print(f"RESULT\n{result}")
25
-
26
- return {
27
- "generated": result["generated"],
28
- "probability": result["probability"]
29
- }
30
-
31
- # if __name__ == "__main__":
32
- # import uvicorn
33
- # uvicorn.run(app, host="0.0.0.0", port=8000)
 
 
 
 
 
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)