#define train and fit model | |
#differentiate into train and test code | |
# service endpoint in seperate code- pass inputs to model convert it into json | |
import pandas as pd | |
import pickle | |
from flask import Flask, request, jsonify | |
# Create a Flask app | |
app = Flask(__name__) | |
# Load the machine learning model from a pickle file | |
model = pickle.load(open("model.pkl", "rb")) | |
def api_health(): | |
return jsonify(Message="Success") | |
# Define a route for making predictions | |
def predict(): | |
# Get JSON data from the request | |
json_ = request.json | |
# Convert JSON data into a DataFrame | |
df = pd.DataFrame(json_) | |
# Use the loaded model to make predictions on the DataFrame | |
prediction = model.predict(df) | |
# Return the predictions as a JSON response | |
return jsonify({"Prediction": list(prediction)}) | |
# Run the Flask app when this script is executed | |
if __name__ == "__main__": | |
app.run(debug=True) |