Upload app.py with huggingface_hub

#1
Files changed (1) hide show
  1. app.py +28 -0
app.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ from flask import Flask, request, jsonify
3
+ import joblib
4
+
5
+ #Initialize Flask app with a name
6
+ Sales_forecasting_api = Flask("Sales Forecasting API")
7
+
8
+ #Load of the Saved Mpdel Pipeline
9
+ pipeline = joblib.load("superkart_pipeline.pkl")
10
+
11
+ #Home Route
12
+ @Sales_forecasting_api.route("/")
13
+ def home():
14
+ return"Welcome to the SuperKart Sales Prediction API!"
15
+ # Define an endpoint to predict Sales
16
+ @Sales_forecasting_api.route("/predict", methods=["POST"])
17
+ def predict():
18
+ try:
19
+ # Get JSON data from the request
20
+ data = request.get_json()
21
+ # Convert JSON to DataFrame
22
+ input_df = pd.DataFrame([data])
23
+ # Make predictions
24
+ predictions = pipeline.predict(input_df)
25
+ # Return predictions as JSON
26
+ return jsonify({"predictions": predictions.tolist()})
27
+ except Exception as e:
28
+ return jsonify({"error": str(e)})