Upload folder using huggingface_hub
Browse files
app.py
CHANGED
|
@@ -1,7 +1,6 @@
|
|
| 1 |
import joblib
|
| 2 |
import pandas as pd
|
| 3 |
from flask import Flask, request, jsonify
|
| 4 |
-
from datetime import datetime
|
| 5 |
|
| 6 |
# Initialize Flask app
|
| 7 |
super_kart_api = Flask("Super Kart Product Sales Predictor")
|
|
@@ -20,8 +19,6 @@ def predict_product_sales_price():
|
|
| 20 |
# Get JSON data from the request
|
| 21 |
product_data = request.get_json()
|
| 22 |
|
| 23 |
-
Store_Age = datetime.now().year - int(product_data['Store_Establishment_Year'])
|
| 24 |
-
|
| 25 |
# Extract relevant house features from the input data
|
| 26 |
sample = {
|
| 27 |
'Product_Weight': product_data['Product_Weight'],
|
|
@@ -29,7 +26,6 @@ def predict_product_sales_price():
|
|
| 29 |
'Product_Type': product_data['Product_Type'],
|
| 30 |
'Product_MRP': product_data['Product_MRP'],
|
| 31 |
'Store_Id': product_data['Store_Id'],
|
| 32 |
-
'Store_Age': Store_Age,
|
| 33 |
'Store_Size': product_data['Store_Size'],
|
| 34 |
'Store_Location_City_Type': product_data['Store_Location_City_Type'],
|
| 35 |
'Store_Type': product_data['Store_Type']
|
|
@@ -47,7 +43,6 @@ def predict_product_sales_price():
|
|
| 47 |
# Define an endpoint to predict product sales price for a batch of product
|
| 48 |
@super_kart_api.post('/v1/productbatch')
|
| 49 |
def predict_product_batch():
|
| 50 |
-
try:
|
| 51 |
# Get the uploaded CSV file from the request
|
| 52 |
file = request.files['file']
|
| 53 |
|
|
@@ -55,22 +50,18 @@ def predict_product_batch():
|
|
| 55 |
data = pd.read_csv(file)
|
| 56 |
|
| 57 |
input_data = data.copy()
|
| 58 |
-
input_data['Store_Age'] = datetime.now().year - input_data['Store_Establishment_Year']
|
| 59 |
input_data = input_data.drop(['Product_Id','Store_Establishment_Year','Product_Allocated_Area'],axis=1)
|
| 60 |
|
| 61 |
-
|
| 62 |
-
|
| 63 |
# Make predictions for the batch data
|
| 64 |
predictions = model.predict(input_data).tolist()
|
| 65 |
|
| 66 |
# Add predictions to the DataFrame
|
| 67 |
-
|
| 68 |
|
| 69 |
# Convert results to dictionary
|
| 70 |
-
result =
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
return jsonify(result)
|
| 74 |
|
| 75 |
|
| 76 |
# Run the Flask app in debug mode
|
|
|
|
| 1 |
import joblib
|
| 2 |
import pandas as pd
|
| 3 |
from flask import Flask, request, jsonify
|
|
|
|
| 4 |
|
| 5 |
# Initialize Flask app
|
| 6 |
super_kart_api = Flask("Super Kart Product Sales Predictor")
|
|
|
|
| 19 |
# Get JSON data from the request
|
| 20 |
product_data = request.get_json()
|
| 21 |
|
|
|
|
|
|
|
| 22 |
# Extract relevant house features from the input data
|
| 23 |
sample = {
|
| 24 |
'Product_Weight': product_data['Product_Weight'],
|
|
|
|
| 26 |
'Product_Type': product_data['Product_Type'],
|
| 27 |
'Product_MRP': product_data['Product_MRP'],
|
| 28 |
'Store_Id': product_data['Store_Id'],
|
|
|
|
| 29 |
'Store_Size': product_data['Store_Size'],
|
| 30 |
'Store_Location_City_Type': product_data['Store_Location_City_Type'],
|
| 31 |
'Store_Type': product_data['Store_Type']
|
|
|
|
| 43 |
# Define an endpoint to predict product sales price for a batch of product
|
| 44 |
@super_kart_api.post('/v1/productbatch')
|
| 45 |
def predict_product_batch():
|
|
|
|
| 46 |
# Get the uploaded CSV file from the request
|
| 47 |
file = request.files['file']
|
| 48 |
|
|
|
|
| 50 |
data = pd.read_csv(file)
|
| 51 |
|
| 52 |
input_data = data.copy()
|
|
|
|
| 53 |
input_data = input_data.drop(['Product_Id','Store_Establishment_Year','Product_Allocated_Area'],axis=1)
|
| 54 |
|
|
|
|
|
|
|
| 55 |
# Make predictions for the batch data
|
| 56 |
predictions = model.predict(input_data).tolist()
|
| 57 |
|
| 58 |
# Add predictions to the DataFrame
|
| 59 |
+
input_data['Predicted_Product_Sales'] = predictions
|
| 60 |
|
| 61 |
# Convert results to dictionary
|
| 62 |
+
result = input_data.to_dict(orient="records")
|
| 63 |
+
|
| 64 |
+
return jsonify(result)
|
|
|
|
| 65 |
|
| 66 |
|
| 67 |
# Run the Flask app in debug mode
|