Upload folder using huggingface_hub
Browse files
app.py
CHANGED
|
@@ -16,17 +16,18 @@ def home():
|
|
| 16 |
# Define an endpoint to predict churn for a single customer
|
| 17 |
@superkart_product_sales_prediction_api.post('/v1/forecast')
|
| 18 |
def predict_sales_forecast():
|
| 19 |
-
|
|
|
|
| 20 |
This function handles POST requests to the '/v1/forecast' endpoint.
|
| 21 |
It expects a JSON payload containing property details and returns
|
| 22 |
the predicted rental price as a JSON response.
|
| 23 |
-
|
| 24 |
|
| 25 |
# Get JSON data from the request
|
| 26 |
-
|
| 27 |
|
| 28 |
-
|
| 29 |
-
|
| 30 |
'Product_Weight': product_data.get('Product_Weight'),
|
| 31 |
'Product_Sugar_Content': product_data.get('Product_Sugar_Content'),
|
| 32 |
'Product_Allocated_Area': product_data.get('Product_Allocated_Area'),
|
|
@@ -39,18 +40,18 @@ def predict_sales_forecast():
|
|
| 39 |
'Store_Type': product_data.get('Store_Type')
|
| 40 |
}
|
| 41 |
|
| 42 |
-
|
| 43 |
-
|
| 44 |
|
| 45 |
-
|
| 46 |
-
|
| 47 |
|
| 48 |
-
|
| 49 |
-
|
| 50 |
|
| 51 |
|
| 52 |
-
|
| 53 |
-
|
| 54 |
|
| 55 |
@superkart_product_sales_prediction_api.post('/v1/forecastbatch')
|
| 56 |
def predict_sales_forecast_batch():
|
|
|
|
| 16 |
# Define an endpoint to predict churn for a single customer
|
| 17 |
@superkart_product_sales_prediction_api.post('/v1/forecast')
|
| 18 |
def predict_sales_forecast():
|
| 19 |
+
|
| 20 |
+
"""
|
| 21 |
This function handles POST requests to the '/v1/forecast' endpoint.
|
| 22 |
It expects a JSON payload containing property details and returns
|
| 23 |
the predicted rental price as a JSON response.
|
| 24 |
+
"""
|
| 25 |
|
| 26 |
# Get JSON data from the request
|
| 27 |
+
product_data = request.get_json()
|
| 28 |
|
| 29 |
+
# Extract relevant customer features from the input data
|
| 30 |
+
sample = {
|
| 31 |
'Product_Weight': product_data.get('Product_Weight'),
|
| 32 |
'Product_Sugar_Content': product_data.get('Product_Sugar_Content'),
|
| 33 |
'Product_Allocated_Area': product_data.get('Product_Allocated_Area'),
|
|
|
|
| 40 |
'Store_Type': product_data.get('Store_Type')
|
| 41 |
}
|
| 42 |
|
| 43 |
+
# Convert the extracted data into a DataFrame
|
| 44 |
+
input_data = pd.DataFrame([sample])
|
| 45 |
|
| 46 |
+
# Make a churn prediction using the trained model
|
| 47 |
+
predicted_sales = model.predict(input_data).tolist()[0]
|
| 48 |
|
| 49 |
+
# Convert predicted_price to Python float
|
| 50 |
+
predicted_sales = round(float(predicted_sales), 2)
|
| 51 |
|
| 52 |
|
| 53 |
+
# Return the prediction as a JSON response
|
| 54 |
+
return jsonify({'Prediction': predicted_sales})
|
| 55 |
|
| 56 |
@superkart_product_sales_prediction_api.post('/v1/forecastbatch')
|
| 57 |
def predict_sales_forecast_batch():
|