Created
April 23, 2021 21:11
-
-
Save moezali1/4bd5312d27884d7b07f66befcdc28ccf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 1. Library imports | |
import pandas as pd | |
from pycaret.regression import load_model, predict_model | |
from fastapi import FastAPI | |
import uvicorn | |
# 2. Create the app object | |
app = FastAPI() | |
#. Load trained Pipeline | |
model = load_model('diamond-pipeline') | |
# Define predict function | |
@app.post('/predict') | |
def predict(carat_weight, cut, color, clarity, polish, symmetry, report): | |
data = pd.DataFrame([[carat_weight, cut, color, clarity, polish, symmetry, report]]) | |
data.columns = ['Carat Weight', 'Cut', 'Color', 'Clarity', 'Polish', 'Symmetry', 'Report'] | |
predictions = predict_model(model, data=data) | |
return {'prediction': int(predictions['Label'][0])} | |
if __name__ == '__main__': | |
uvicorn.run(app, host='127.0.0.1', port=8000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment