File size: 577 Bytes
9184e73
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from fastapi import FastAPI
from pydantic import BaseModel
from fastapi.responses import JSONResponse
from Paraphrase import paraphrase_paragraph

app = FastAPI()

class Sentence(BaseModel):
    sentence: str


@app.get("/")
def index():
    return "OK"

@app.post("/rephrase")
def rephrase(sentence: Sentence):
    try:
        rephrase_text = paraphrase_paragraph(sentence.sentence)
        return JSONResponse(status_code=200, content={"rephrased_sentence": rephrase_text})
    except Exception as e:
        return JSONResponse(status_code=422,content="Unable to rephrase")