Spaces:
Runtime error
Runtime error
Upload folder using huggingface_hub
Browse files- app.py +11 -10
- nozzle_selection.joblib +2 -2
app.py
CHANGED
|
@@ -6,10 +6,10 @@ import pandas as pd # For data manipulation
|
|
| 6 |
from flask import Flask, request, jsonify # For creating the Flask API
|
| 7 |
|
| 8 |
# Initialize Flask app with a name
|
| 9 |
-
nozzleselect_api = Flask("
|
| 10 |
|
| 11 |
# Load the trained prediction model
|
| 12 |
-
model = joblib.load("
|
| 13 |
|
| 14 |
# Define a route for the home page
|
| 15 |
@nozzleselect_api.get('/')
|
|
@@ -18,10 +18,10 @@ def home():
|
|
| 18 |
This function handles GET requests to the root URL ('/') of the API.
|
| 19 |
It returns a simple welcome message.
|
| 20 |
"""
|
| 21 |
-
return "Welcome to
|
| 22 |
|
| 23 |
# Define an endpoint to predict churn for a single customer
|
| 24 |
-
@
|
| 25 |
def predict_nozzle():
|
| 26 |
"""
|
| 27 |
This function handles POST requests to the '/v1/predict' endpoint.
|
|
@@ -33,9 +33,11 @@ def predict_nozzle():
|
|
| 33 |
|
| 34 |
# Extract relevant product ans store features from the input data. The order of the column names matters.
|
| 35 |
sample = {
|
|
|
|
| 36 |
'cg': data['cg'],
|
| 37 |
'cg_fw': data['cg_fw'],
|
| 38 |
-
'
|
|
|
|
| 39 |
}
|
| 40 |
|
| 41 |
|
|
@@ -48,11 +50,10 @@ def predict_nozzle():
|
|
| 48 |
# Return the prediction as a JSON response
|
| 49 |
return jsonify({'nozzle': prediction})
|
| 50 |
|
|
|
|
| 51 |
# Define an endpoint for batch prediction (POST request)
|
| 52 |
@nozzleselect_api.post('/v1/predictbatch')
|
| 53 |
-
|
| 54 |
-
"""
|
| 55 |
-
def predict_sales_batch():
|
| 56 |
"""
|
| 57 |
This function handles POST requests to the '/v1/predictbatch' endpoint.
|
| 58 |
It expects a CSV file containing property details for multiple properties
|
|
@@ -65,10 +66,10 @@ def predict_sales_batch():
|
|
| 65 |
input_data = pd.read_csv(file)
|
| 66 |
|
| 67 |
# Make predictions for all properties in the DataFrame
|
| 68 |
-
|
| 69 |
|
| 70 |
# Return the prediction as a JSON response
|
| 71 |
-
return jsonify({'
|
| 72 |
|
| 73 |
"""
|
| 74 |
|
|
|
|
| 6 |
from flask import Flask, request, jsonify # For creating the Flask API
|
| 7 |
|
| 8 |
# Initialize Flask app with a name
|
| 9 |
+
nozzleselect_api = Flask("ABM Nozzle Selection") #define the name of the app
|
| 10 |
|
| 11 |
# Load the trained prediction model
|
| 12 |
+
model = joblib.load("nozzle_selection_prediction_model.joblib") #define the location of the serialized model
|
| 13 |
|
| 14 |
# Define a route for the home page
|
| 15 |
@nozzleselect_api.get('/')
|
|
|
|
| 18 |
This function handles GET requests to the root URL ('/') of the API.
|
| 19 |
It returns a simple welcome message.
|
| 20 |
"""
|
| 21 |
+
return "Welcome to ABM's Nozzle Select Predictor API!" #define a welcome message
|
| 22 |
|
| 23 |
# Define an endpoint to predict churn for a single customer
|
| 24 |
+
@nozzleselect_api_api.post('/v1/predict')
|
| 25 |
def predict_nozzle():
|
| 26 |
"""
|
| 27 |
This function handles POST requests to the '/v1/predict' endpoint.
|
|
|
|
| 33 |
|
| 34 |
# Extract relevant product ans store features from the input data. The order of the column names matters.
|
| 35 |
sample = {
|
| 36 |
+
'nozzle': data['nozzle'],
|
| 37 |
'cg': data['cg'],
|
| 38 |
'cg_fw': data['cg_fw'],
|
| 39 |
+
'Decide': data['Decide']
|
| 40 |
+
|
| 41 |
}
|
| 42 |
|
| 43 |
|
|
|
|
| 50 |
# Return the prediction as a JSON response
|
| 51 |
return jsonify({'nozzle': prediction})
|
| 52 |
|
| 53 |
+
"""
|
| 54 |
# Define an endpoint for batch prediction (POST request)
|
| 55 |
@nozzleselect_api.post('/v1/predictbatch')
|
| 56 |
+
def predict_nozzle_batch():
|
|
|
|
|
|
|
| 57 |
"""
|
| 58 |
This function handles POST requests to the '/v1/predictbatch' endpoint.
|
| 59 |
It expects a CSV file containing property details for multiple properties
|
|
|
|
| 66 |
input_data = pd.read_csv(file)
|
| 67 |
|
| 68 |
# Make predictions for all properties in the DataFrame
|
| 69 |
+
predicted_nozzle = model.predict(input_data).tolist()
|
| 70 |
|
| 71 |
# Return the prediction as a JSON response
|
| 72 |
+
return jsonify({'nozzle': predicted_nozzle})
|
| 73 |
|
| 74 |
"""
|
| 75 |
|
nozzle_selection.joblib
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:025c6acdf8595d9180d84372d7882c5d499461a9ee7039d84a91aa4d098b311c
|
| 3 |
+
size 51899
|