Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,19 +4,16 @@ from flask import Flask, request, jsonify
|
|
| 4 |
|
| 5 |
app = Flask(__name__)
|
| 6 |
|
| 7 |
-
# Initialize Flask app with a name
|
| 8 |
-
churn_predictor_api = Flask("Customer Churn Predictor")
|
| 9 |
-
|
| 10 |
# Load the trained churn prediction model
|
| 11 |
model = joblib.load("churn_prediction_model_v1_0.joblib")
|
| 12 |
|
| 13 |
# Define a route for the home page
|
| 14 |
-
@
|
| 15 |
def home():
|
| 16 |
return "Welcome to the Customer Churn Prediction API!"
|
| 17 |
|
| 18 |
# Define an endpoint to predict churn for a single customer
|
| 19 |
-
@
|
| 20 |
def predict_churn():
|
| 21 |
# Get JSON data from the request
|
| 22 |
customer_data = request.get_json()
|
|
@@ -47,7 +44,7 @@ def predict_churn():
|
|
| 47 |
return jsonify({'Prediction': prediction_label})
|
| 48 |
|
| 49 |
# Define an endpoint to predict churn for a batch of customers
|
| 50 |
-
@
|
| 51 |
def predict_churn_batch():
|
| 52 |
# Get the uploaded CSV file from the request
|
| 53 |
file = request.files['file']
|
|
@@ -69,4 +66,4 @@ def predict_churn_batch():
|
|
| 69 |
|
| 70 |
# Run the Flask app in debug mode
|
| 71 |
if __name__ == '__main__':
|
| 72 |
-
app.run(debug=True)
|
|
|
|
| 4 |
|
| 5 |
app = Flask(__name__)
|
| 6 |
|
|
|
|
|
|
|
|
|
|
| 7 |
# Load the trained churn prediction model
|
| 8 |
model = joblib.load("churn_prediction_model_v1_0.joblib")
|
| 9 |
|
| 10 |
# Define a route for the home page
|
| 11 |
+
@app.get('/')
|
| 12 |
def home():
|
| 13 |
return "Welcome to the Customer Churn Prediction API!"
|
| 14 |
|
| 15 |
# Define an endpoint to predict churn for a single customer
|
| 16 |
+
@app.post('/v1/customer')
|
| 17 |
def predict_churn():
|
| 18 |
# Get JSON data from the request
|
| 19 |
customer_data = request.get_json()
|
|
|
|
| 44 |
return jsonify({'Prediction': prediction_label})
|
| 45 |
|
| 46 |
# Define an endpoint to predict churn for a batch of customers
|
| 47 |
+
@app.post('/v1/customerbatch')
|
| 48 |
def predict_churn_batch():
|
| 49 |
# Get the uploaded CSV file from the request
|
| 50 |
file = request.files['file']
|
|
|
|
| 66 |
|
| 67 |
# Run the Flask app in debug mode
|
| 68 |
if __name__ == '__main__':
|
| 69 |
+
app.run(host="0.0.0.0", port=7860, debug=True)
|