-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
43 lines (27 loc) · 885 Bytes
/
app.py
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
import os
from fastapi import FastAPI
from fastapi.responses import RedirectResponse, Response
import uvicorn
from textSummarizer.pipeline.model_inference_pipeline import ModelInferencePipeline
app = FastAPI()
#* Redirect to docs
@app.get("/", tags=["Authentication"])
async def index():
return RedirectResponse(url="/docs")
@app.get("/train", tags=["Training"])
async def training():
try:
os.system("python main.py")
return Response("Training successful!")
except Exception as e:
return Response(f"Error occurred: {e}")
@app.post("/predict", tags=["Inference"])
async def predict_route(text):
try:
obj = ModelInferencePipeline()
text = obj.main(input_text=text)
return text
except Exception as e:
raise e
if __name__ == "__main__":
uvicorn.run(app, host='0.0.0.0', port=8000)