-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
44 lines (33 loc) · 1.06 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
# 1. Install uvicorn and fastapi
# pip install fastapi uvicorn
# 1. Imports Libraries
import uvicorn
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
import pickle
# 2. Create the app object
app = FastAPI()
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
#3.load the model
rgModel = pickle.load(open("1024.pkl", "rb"))
# 4. Index route, opens automatically on http://127.0.0.1:80
@app.get('/')
def index():
return {'message': 'Hello, World'}
# 5. Run the API with uvicorn
if __name__ == '__main__':
uvicorn.run(app, port=80, host='0.0.0.0')
#----------------------
@app.get("/predictProbability")
def gePredictProbability(GRE: int, TOEFL: int,Rating: int,CGPA: float):
#rgModel = pickle.load(open("1024.pkl", "rb"))
prediction = rgModel.predict([[GRE,TOEFL,Rating,CGPA]])
return {'prediction': prediction[0]}
# uvicorn app:app --host 0.0.0.0 --port 80
# http://127.0.0.1/predictProbability?GRE=324&TOEFL=107&Rating=1&CGPA=8.87