Skip to content

Instantly share code, notes, and snippets.

@moezali1
Created April 23, 2021 21:11
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moezali1/4bd5312d27884d7b07f66befcdc28ccf to your computer and use it in GitHub Desktop.
Save moezali1/4bd5312d27884d7b07f66befcdc28ccf to your computer and use it in GitHub Desktop.
# 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