CoolFace
Apppublic

Georgek17/RevenuePredictor

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
app.py51 linesDownload Raw Back to root
1import joblib
2import pandas as pd
3from flask import Flask, request, jsonify
4
5# Initialize Flask app with a name
6SalesRevenue_predictor_api = Flask("Sales Revenue predictor")
7
8# Load the trained revenue prediction model
9model = joblib.load("SuperKart_turnOver_prediction_model_v1_0.joblib")
10
11# Define a route for the home page
12@SalesRevenue_predictor_api.get('/')
13def home():
14    return "Welcome to the Sales Revenue Prediction API!"
15
16# Define an endpoint to predict revenue for a single customer
17@SalesRevenue_predictor_api.route('/v1/Sales_prediction', methods=['POST'])
18def predict_revenue():
19    # Get JSON data from the request
20    product_data = request.get_json()
21
22    # Extract relevant customer features from the input data
23    sample = {
24        'Product_Id': product_data['Product_Id'],
25        'Product_Weight': product_data['Product_Weight'],
26        'Product_Sugar_Content': product_data['Product_Sugar_Content'],
27        'Product_Allocated_Area': product_data['Product_Allocated_Area'],
28        'Product_Type': product_data['Product_Type'],
29        'Product_MRP': product_data['Product_MRP'],
30        'Store_Id': product_data['Store_Id'],
31        'Store_Establishment_Year': product_data['Store_Establishment_Year'],
32        'Store_Size': product_data['Store_Size'],
33        'Store_Location_City_Type': product_data['Store_Location_City_Type'],
34        'Store_Type' : product_data['Store_Type']
35    }
36
37    # Convert the extracted data into a DataFrame
38    input_data = pd.DataFrame([sample])
39
40    # Make a revenue prediction using the trained model
41    #prediction = model.predict(input_data).tolist()[0]
42    prediction = model.predict(input_data)[0]
43
44    # Return the prediction as a JSON response
45    return jsonify({ 'Prediction': prediction, 'Message': 'Prediction completed' })
46
47
48# Run the Flask app in debug mode
49if __name__ == '__main__':
50    SalesRevenue_predictor_api.run(debug=True)
51