File size: 806 Bytes
205ca7f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 flask
import joblib
import pandas as pd

# Load the trained model
model = joblib.load('tuned_random_forest_model.pkl') # Replace with the actual model filename

app = flask.Flask(__name__)

@app.route('/')
def home():
    return "Lead Conversion Prediction Backend"

@app.route('/predict', methods=['POST'])
def predict():
    try:
        # Get the data from the request
        data = flask.request.get_json(force=True)
        df_predict = pd.DataFrame(data)

        # Make predictions
        predictions = model.predict(df_predict)

        # Return the predictions as JSON
        return flask.jsonify(predictions.tolist())

    except Exception as e:
        return flask.jsonify({'error': str(e)})

if __name__ == '__main__':
    # Run the Flask app
    app.run(host='0.0.0.0', port=5000)