This repository was archived by the owner on Sep 7, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathserver.py
More file actions
92 lines (77 loc) · 2.83 KB
/
server.py
File metadata and controls
92 lines (77 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
from fastapi import FastAPI, HTTPException, status
from fastapi.encoders import jsonable_encoder
from pydantic import BaseModel
import os
import sys
sys.path.append(os.path.join(os.path.dirname(__file__), os.path.pardir))
from langdetect import detect
from gptzero import ZeroAccount, ZeroVerdict, ZeroVerdictData
from zeroGPT import zeroGPTVerdict
from paraphraser import Paraphraser
from plagiarism import turnitinPlagaiarsimChecker
from enum import Enum
class ParaphraserModes(Enum):
Regular = 1
Formal = 2
TextOptimizer = 3
Smarter = 4
Creative = 5
AiParaphrase = 6
class Content(BaseModel):
content: str
class ParaphraserContent(BaseModel):
content: str
mode: ParaphraserModes
paraph = Paraphraser()
app = FastAPI()
@app.post("/gptzero/scan/", response_model=ZeroVerdictData)
def gpt_zero_scan(content: Content):
acc = ZeroAccount.get_from_local()
if not acc:
acc = ZeroAccount.create()
res = ZeroVerdict.get(jsonable_encoder(content)["content"], acc)
if res:
return res
raise HTTPException(status_code=500, detail="Something went wrong please check logs")
@app.post("/zerogpt/scan/")
def zero_gpt_scan(content: Content):
res = zeroGPTVerdict(jsonable_encoder(content)["content"])
if res:
return res
raise HTTPException(status_code=500, detail="Something went wrong please check logs")
@app.post("/turnitinPlagiarism/scan/")
def zero_gpt_scan(content: Content):
inp = jsonable_encoder(content)["content"]
res = turnitinPlagaiarsimChecker(inp, detect(inp))
if res:
return res
raise HTTPException(status_code=500, detail="Something went wrong please check logs")
@app.post("/paraphrase/")
def paraphraser(content: ParaphraserContent):
inp = jsonable_encoder(content)
res = paraph.paraphrase(inp["content"], detect(inp["content"]), str(inp["mode"]))
if res:
return {"paraphraser": res}
raise HTTPException(status_code=500, detail="Something went wrong please check logs")
class HealthCheck(BaseModel):
"""Response model to validate and return when performing a health check."""
status: str = "OK"
@app.get(
"/health",
tags=["healthcheck"],
summary="Perform a Health Check",
response_description="Return HTTP Status Code 200 (OK)",
status_code=status.HTTP_200_OK,
response_model=HealthCheck,
)
def get_health() -> HealthCheck:
"""
## Perform a Health Check
Endpoint to perform a healthcheck on. This endpoint can primarily be used Docker
to ensure a robust container orchestration and management is in place. Other
services which rely on proper functioning of the API service will not deploy if this
endpoint returns any other HTTP status code except 200 (OK).
Returns:
HealthCheck: Returns a JSON response with the health status
"""
return HealthCheck(status="OK")