Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import uvicorn
|
2 |
+
import globals
|
3 |
+
from rephrase.rephrase_text import rephraseText, rephraseText_withStream
|
4 |
+
from fastapi import FastAPI
|
5 |
+
from fastapi.middleware.cors import CORSMiddleware
|
6 |
+
from fastapi.responses import StreamingResponse
|
7 |
+
from models.rephraseparam import rephraseparam
|
8 |
+
|
9 |
+
app = FastAPI()
|
10 |
+
|
11 |
+
app.add_middleware(
|
12 |
+
CORSMiddleware,
|
13 |
+
allow_origins=["*"],
|
14 |
+
allow_credentials=True,
|
15 |
+
allow_methods=["*"],
|
16 |
+
allow_headers=["*"],
|
17 |
+
)
|
18 |
+
|
19 |
+
#TODO: add logging for exception and openai call backs
|
20 |
+
@app.get("/cmsai/isconfigkeyavailable")
|
21 |
+
def isConfigKeyAvailable():
|
22 |
+
SECRET_KEY = globals.OPENAI_API_KEY
|
23 |
+
if SECRET_KEY != "" and len(SECRET_KEY.strip()) > 0:
|
24 |
+
return "API KEY IS CONFIGURED"
|
25 |
+
else:
|
26 |
+
return "API KEY IS NOT CONFIGURED"
|
27 |
+
|
28 |
+
|
29 |
+
@app.post("/cmsai/summarizetext")
|
30 |
+
async def summarizetext(param:rephraseparam):
|
31 |
+
text_summary = rephraseText(param)
|
32 |
+
return text_summary
|
33 |
+
|
34 |
+
@app.post("/cmsai/summarizetextwithstreaming")
|
35 |
+
async def summarizetext_stream(param:rephraseparam):
|
36 |
+
summary_inChunks = rephraseText_withStream(param)
|
37 |
+
return StreamingResponse(summary_inChunks, media_type= "text/plain")
|
38 |
+
|
39 |
+
|
40 |
+
if __name__ == "__main__":
|
41 |
+
uvicorn.run(app= app)
|