File size: 1,763 Bytes
6e01b8a
 
 
46c9645
6e01b8a
 
 
 
 
 
 
 
 
 
 
 
 
 
46c9645
6e01b8a
 
 
 
 
 
 
 
 
 
 
 
 
 
a0eabe8
6e01b8a
 
 
 
 
46c9645
8adb9eb
6e01b8a
 
 
 
 
 
97e0dae
6e01b8a
79b8f4f
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
import joblib
import pandas as pd
from flask import Flask, request, jsonify
import numpy as np

# Initialize Flask app with a name
app = Flask("SuperKart sales prediction app backend")

# Load the trained churn prediction model
model = joblib.load("SuperKart_model_deployment_model_v1_0.joblib")

# Define a route for the home page
@app.get('/')
def home():
    return "Welcome to the SuperKart Sales Prediction API"

# Define an endpoint to predict sales of the single product in a store
@app.post('/v1/sales')
def predict_sales():
    # Get JSON data from the request
    store_data = request.get_json()

    # Extract relevant store features from the input data
    requestData = {
        'Product_Weight': store_data['Product_Weight'],
        'Product_Sugar_Content': store_data['Product_Sugar_Content'],
        'Product_Allocated_Area': store_data['Product_Allocated_Area'],
        'Product_Type': store_data['Product_Type'],
        'Product_MRP': store_data['Product_MRP'],
        'Store_Id': store_data['Store_Id'],
        'Store_Establishment_Year': store_data['Store_Establishment_Year'],
        'Store_Size': store_data['Store_Size'],
        'Store_Location_City_Type': store_data['Store_Location_City_Type'],
        'Store_Type': store_data['Store_Type']
    }

    # Convert the extracted data into a DataFrame
    input_data = pd.DataFrame([requestData])

    # Make a Sales prediction using the trained model
    prediction = model.predict(input_data).tolist()[0]

    #Calculate the actual price
    predicted_sales = np.exp(prediction)

    # Convert predicted_price to Python float
    predicted_sales = round(float(predicted_sales), 2)

    # Return the prediction as a JSON response
    return jsonify({'Predicted_Sale': prediction})