File size: 1,145 Bytes
3fa9533
 
 
49c1eb7
 
 
 
 
 
 
 
3fa9533
9146e82
8dc82de
3fa9533
e4273e0
 
 
1724a3d
a752b67
1724a3d
 
 
 
 
 
8dc82de
1724a3d
 
69d2aec
da64840
 
 
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
import joblib
import pandas as pd
from flask import Flask, request, jsonify
# Libraries different ensemble classifiers
from sklearn.ensemble import (
    BaggingRegressor,
    RandomForestRegressor,
    AdaBoostRegressor,
    GradientBoostingRegressor,
)
import xgboost as xgb
# Initialize Flask app
app = Flask("Supermarket Product Price Predictor")
loaded_model  = joblib.load("predict_product_price_v1_0.joblib")
# Define a route for the home page
# @sapp.get('/')
# def home():
#     return "Welcome to the Supermarket Product Price Predictor!"
# Define an endpoint 
@app.post('/price')
def predict_price():
    # Get JSON data from the request
    input_json = request.get_json()
    # Convert the extracted data into a DataFrame
    input_data = pd.DataFrame([input_json])
    # Make a churn prediction using the trained model
    prediction = loaded_model.predict(input_data)
    # Return the prediction as a JSON response
    return jsonify({'Price': prediction})
##
if __name__ == '__main__':
    # Run the app on all available interfaces on port 5000
    app.run(debug=True, host='0.0.0.0', port=5000)