-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
25 lines (19 loc) · 829 Bytes
/
Copy pathapp.py
File metadata and controls
25 lines (19 loc) · 829 Bytes
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
from flask import Flask, request, jsonify
import joblib
import pandas as pd
import logging
logging.basicConfig(level=logging.INFO)
app = Flask(__name__)
# Load the entire pipeline
pipeline = joblib.load('rf_model.pkl') # Ensure this points to the correct pipeline file
# Define a route for making predictions
@app.route('/predict', methods=['POST'])
def predict():
data = request.get_json() # Get input data from POST request
# Convert the input data to a DataFrame
input_df = pd.DataFrame(data['input'])
# Make a prediction using the pipeline
prediction = pipeline.predict(input_df) # Ensure you're calling predict on the pipeline
return jsonify({'prediction': int(prediction[0])}) # Return the prediction as JSON
if __name__ == '__main__':
app.run(debug=True)