Spaces:
Sleeping
Sleeping
| import joblib | |
| import pandas as pd | |
| from flask import Flask, request, jsonify | |
| # Initialize Flask app with a name | |
| app = Flask("SuperKart Sales Predictor") | |
| # Load the trained sales prediction model | |
| model = joblib.load("superkart_sales_prediction_model_v1_0.joblib") | |
| # Define a route for the home page | |
| def home(): | |
| return "Welcome to the SuperKart Sales Prediction API" | |
| def mytest(): | |
| return "this is testing" | |
| # Define an endpoint to predict sales | |
| def totalsales(): | |
| # Get JSON data from the request | |
| sales_data = request.get_json() | |
| # Extract relevant sales features from the input data | |
| sample = { | |
| 'Product_Weight': sales_data['Product_Weight'], | |
| 'Product_Sugar_Content': sales_data['Product_Sugar_Content'], | |
| 'Product_Allocated_Area': sales_data['Product_Allocated_Area'], | |
| 'Product_Type': sales_data['Product_Type'], | |
| 'Product_MRP': sales_data['Product_MRP'], | |
| 'Store_Id': sales_data['Store_Id'], | |
| 'Store_Establishment_Year': sales_data['Store_Establishment_Year'], | |
| 'Store_Size': sales_data['Store_Size'], | |
| 'Store_Location_City_Type': sales_data['Store_Location_City_Type'], | |
| 'Store_Type': sales_data['Store_Type'] | |
| } | |
| # Convert the extracted data into a DataFrame | |
| input_data = pd.DataFrame([sample]) | |
| # Make a sales prediction using the trained model | |
| prediction = model.predict(input_data)[0] | |
| # Return the prediction as a JSON response | |
| return jsonify({'predicted_sales': float(round(prediction, 2))}) | |
| # Run the Flask app in debug mode | |
| #if __name__ == '__main__': | |
| # app.run(debug=True) | |