Spaces:
Build error
Build error
File size: 1,780 Bytes
2dedb84 e2f90a2 2dedb84 e4644ee 2dedb84 e4644ee 2dedb84 e4644ee 2dedb84 e4644ee 2dedb84 e4644ee 2dedb84 | 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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | # Import necessary libraries
import numpy as np
import joblib # For loading the serialized model
import pandas as pd # For data manipulation
from flask import Flask, request, jsonify # For creating the Flask API
# Initialize the Flask app
app = Flask(__name__)
model = joblib.load("backend_files/superkart_sales_prediction_model_v1_0.joblib")
# Define a route for the home page (GET request)
@store_sales_api.post('/v1/sale')
def predict_store_sales():
"""
Handles POST requests for predicting sales of a single store.
Expects JSON input with store details.
"""
# Get JSON input
store_data = request.get_json()
# Extract relevant features (match your model training columns)
sample = {
'Product_Weight': store_data['Product_Weight'],
'Product_Allocated_Area': store_data['Product_Allocated_Area'],
'Product_MRP': store_data['Product_MRP'],
'Store_Age': store_data['Store_Age'],
'Product_Sugar_Content': store_data['Product_Sugar_Content'],
'Product_Type': store_data['Product_Type'],
'Store_Size': store_data['Store_Size'],
'Store_Location_City_Type': store_data['Store_Location_City_Type'],
'Store_Type': store_data['Store_Type'],
'Store_Id': store_data['Store_Id']
}
# Convert into DataFrame
input_data = pd.DataFrame([sample])
# Make prediction
predicted_sales = model.predict(input_data)[0]
# Convert to Python float and round
predicted_sales = round(float(predicted_sales), 2)
# Return JSON response
return jsonify({'Predicted Store Sales': predicted_sales})
# ...existing code...
# Run Flask app
if __name__ == '__main__':
store_sales_api.run(debug=True)
|