Commit ade817f3 authored by Anuththara18's avatar Anuththara18

fastapi codes added

parent 242e6086
...@@ -2,10 +2,20 @@ from fastapi import FastAPI ...@@ -2,10 +2,20 @@ from fastapi import FastAPI
import uvicorn import uvicorn
import pickle import pickle
from models import Performance from models import Performance
from famodel import FAPerformance
from seamodel import SEAPerformance
from suamodel import SUAPerformance
app=FastAPI() app = FastAPI()
modelaa1 = pickle.load(open("modelaa1.sav", "rb"))
modelaa2 = pickle.load(open("modelaa2.sav", "rb"))
modelsea = pickle.load(open("modelsea.sav", "rb"))
modelsua = pickle.load(open("modelsua.sav", "rb"))
modelda = pickle.load(open("modelda.sav", "rb"))
modelfa1 = pickle.load(open("modelfa1.sav", "rb"))
modelfa2 = pickle.load(open("modelfa2.sav", "rb"))
model=pickle.load(open("selectivemodel.sav", "rb"))
@app.get("/{name}") @app.get("/{name}")
async def hello(name): async def hello(name):
...@@ -15,7 +25,21 @@ async def hello(name): ...@@ -15,7 +25,21 @@ async def hello(name):
async def greet(): async def greet():
return {"Hello World!"} return {"Hello World!"}
@app.post("/predict") @app.post("/aa1predict")
async def predict(req:Performance):
age=req.age
mrt=req.mrt
pcr=req.pcr
oer=req.oer
cer=req.cer
features=list([age,mrt,pcr,oer,cer])
predict=modelaa1.predict([features])
if(predict==0):
return {"{}".format(predict)}
else:
return {"{}".format(predict)}
@app.post("/aa2predict")
async def predict(req:Performance): async def predict(req:Performance):
age=req.age age=req.age
mrt=req.mrt mrt=req.mrt
...@@ -23,15 +47,91 @@ async def predict(req:Performance): ...@@ -23,15 +47,91 @@ async def predict(req:Performance):
oer=req.oer oer=req.oer
cer=req.cer cer=req.cer
features=list([age,mrt,pcr,oer,cer]) features=list([age,mrt,pcr,oer,cer])
predict=model.predict([features]) predict=modelaa2.predict([features])
if(predict==1): if(predict==0):
return {"Ans 1 {}".format(predict)} return {"{}".format(predict)}
elif (predict==1):
return {"{}".format(predict)}
else:
return {"{}".format(predict)}
@app.post("/dapredict")
async def predict(req:Performance):
age=req.age
mrt=req.mrt
pcr=req.pcr
oer=req.oer
cer=req.cer
features=list([age,mrt,pcr,oer,cer])
predict=modelda.predict([features])
if(predict==0):
return {"{}".format(predict)}
else:
return {"{}".format(predict)}
@app.post("/faonepredict")
async def predict(req:FAPerformance):
age=req.age
mrt=req.mrt
pcr=req.pcr
oer=req.oer
features=list([age,mrt,pcr,oer])
predict=modelfa1.predict([features])
if(predict==0):
return {"{}".format(predict)}
else:
return {"{}".format(predict)}
@app.post("/fatwopredict")
async def predict(req:FAPerformance):
age=req.age
mrt=req.mrt
pcr=req.pcr
oer=req.oer
features=list([age,mrt,pcr,oer])
predict=modelfa2.predict([features])
if(predict==0):
return {"{}".format(predict)}
else:
return {"{}".format(predict)}
@app.post("/seapredict")
async def predict(req:SEAPerformance):
age=req.age
td=req.td
pcr=req.pcr
oer=req.oer
cer=req.cer
features=list([age,td,pcr,oer,cer])
predict=modelsea.predict([features])
if(predict==0):
return {"{}".format(predict)}
elif (predict==1):
return {"{}".format(predict)}
elif (predict==2): elif (predict==2):
return {"Ans 2 {}".format(predict)} return {"{}".format(predict)}
elif (predict==3):
return {"Ans 3 {}".format(predict)}
else: else:
return {"Ans 4 {}".format(predict)} return {"{}".format(predict)}
@app.post("/suapredict")
async def predict(req:SUAPerformance):
age=req.age
mrt=req.mrt
pcr=req.pcr
oer=req.oer
td=req.td
features=list([age,mrt,pcr,oer,td])
predict=modelsua.predict([features])
if(predict==0):
return {"{}".format(predict)}
elif (predict==1):
return {"{}".format(predict)}
else:
return {"{}".format(predict)}
"""
if __name__=="__main__": if __name__=="__main__":
uvicorn.run(app, host="127.0.0.1", port=5049) uvicorn.run(app, host="127.0.0.1", port=5049)
"""
\ No newline at end of file
from pydantic import BaseModel
class FAPerformance(BaseModel):
age: int
mrt: float
pcr: float
oer: float
from pydantic import BaseModel
class SEAPerformance(BaseModel):
age: int
td: float
pcr: float
oer: float
cer: float
from pydantic import BaseModel
class SUAPerformance(BaseModel):
age: int
mrt: float
pcr: float
oer: float
td: float
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment