-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
52 lines (33 loc) · 1.09 KB
/
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
44
45
46
47
48
49
50
51
52
from hate.pipeline.train_pipeline import TrainPipeline
from fastapi import FastAPI
import uvicorn
import sys
from fastapi.templating import Jinja2Templates
from starlette.responses import RedirectResponse
from fastapi.responses import Response
from hate.pipeline.prediction_pipeline import PredictionPipeline
from hate.exception import CustomException
from hate.constants import *
text:str = "What is machine learing?"
app = FastAPI()
@app.get("/", tags=["authentication"])
async def index():
return RedirectResponse(url="/docs")
@app.get("/train")
async def training():
try:
train_pipeline = TrainPipeline()
train_pipeline.run_pipeline()
return Response("Training successful !!")
except Exception as e:
return Response(f"Error Occurred! {e}")
@app.post("/predict")
async def predict_route(text):
try:
obj = PredictionPipeline()
text = obj.run_pipeline(text)
return text
except Exception as e:
raise CustomException(e, sys) from e
if __name__=="__main__":
uvicorn.run(app, host=APP_HOST, port=APP_PORT)