KoulVivek's picture
Upload folder using huggingface_hub
cac2225 verified
import pandas as pd
import joblib
import numpy as np
from flask import Flask, request, jsonify
# Initialize Flask app with a name
app = Flask("SuperKart Sales Predictor")
# Load the trained churn prediction model
model = joblib.load("sales_prediction_model_v1_0.joblib")
# Define a route for the home page
@app.get('/')
def home():
return "Welcome to the Sales Prediction API"
# Define an endpoint to predict sales
@app.post('/v1/sales')
def predict_sales():
# Get JSON data from the request
data = request.get_json()
print(data)
# Extract relevant customer features from the input data
sample = {
'Product_Weight': data['Product_Weight'],
'Product_Sugar_Content': data['Product_Sugar_Content'],
'Product_Allocated_Area': data['Product_Allocated_Area'],
'Product_MRP': data['Product_MRP'],
'Store_Size': data['Store_Size'],
'Store_Location_City_Type': data['Store_Location_City_Type'],
'Store_Type': data['Store_Type'],
'category': data['category'],
'Product_Type_category': data['Product_Type_category'],
'Store_Establishment_Year':1999,
'Product_Id':"",
'Store_Id':"",
'Product_Type':""}
print(sample)
# Convert the extracted data into a DataFrame
input_data = pd.DataFrame([sample])
# Make a churn prediction using the trained model
prediction = model.predict(input_data).tolist()[0]
# Map prediction result to a human-readable label
# Return the sales prediction as a JSON response
return jsonify({'Sales': prediction})
# Run the Flask app in debug mode
if __name__ == '__main__':
app.run(debug=True)