Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# 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