Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files
app.py
CHANGED
|
@@ -1,5 +1,4 @@
|
|
| 1 |
|
| 2 |
-
import os
|
| 3 |
from flask import Flask, request, jsonify
|
| 4 |
import pandas as pd
|
| 5 |
import joblib
|
|
@@ -11,8 +10,6 @@ import json
|
|
| 11 |
logging.basicConfig(level=logging.INFO)
|
| 12 |
logger = logging.getLogger(__name__)
|
| 13 |
|
| 14 |
-
#os.makedirs('backend_deployment', exist_ok=True)
|
| 15 |
-
|
| 16 |
# Initialize Flask app
|
| 17 |
app = Flask(__name__)
|
| 18 |
|
|
@@ -149,17 +146,26 @@ def batch_predict():
|
|
| 149 |
|
| 150 |
for i, item in enumerate(data['predictions']):
|
| 151 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 152 |
# Create DataFrame for prediction
|
| 153 |
input_data = pd.DataFrame([{
|
|
|
|
| 154 |
'Product_Weight': float(item['Product_Weight']),
|
| 155 |
'Product_Sugar_Content': str(item['Product_Sugar_Content']),
|
| 156 |
'Product_Allocated_Area': float(item['Product_Allocated_Area']),
|
| 157 |
'Product_Type': str(item['Product_Type']),
|
| 158 |
'Product_MRP': float(item['Product_MRP']),
|
|
|
|
| 159 |
'Store_Establishment_Year': int(item['Store_Establishment_Year']),
|
| 160 |
'Store_Size': str(item['Store_Size']),
|
| 161 |
'Store_Location_City_Type': str(item['Store_Location_City_Type']),
|
| 162 |
-
'Store_Type': str(item['Store_Type'])
|
|
|
|
|
|
|
| 163 |
}])
|
| 164 |
|
| 165 |
prediction = model.predict(input_data)[0]
|
|
|
|
| 1 |
|
|
|
|
| 2 |
from flask import Flask, request, jsonify
|
| 3 |
import pandas as pd
|
| 4 |
import joblib
|
|
|
|
| 10 |
logging.basicConfig(level=logging.INFO)
|
| 11 |
logger = logging.getLogger(__name__)
|
| 12 |
|
|
|
|
|
|
|
| 13 |
# Initialize Flask app
|
| 14 |
app = Flask(__name__)
|
| 15 |
|
|
|
|
| 146 |
|
| 147 |
for i, item in enumerate(data['predictions']):
|
| 148 |
try:
|
| 149 |
+
# Calculate derived features
|
| 150 |
+
current_year = 2025
|
| 151 |
+
store_age = current_year - int(item['Store_Establishment_Year'])
|
| 152 |
+
price_efficiency = float(item['Product_MRP']) * 0.1
|
| 153 |
+
|
| 154 |
# Create DataFrame for prediction
|
| 155 |
input_data = pd.DataFrame([{
|
| 156 |
+
'Product_Id': f'FD{i+1:03d}', # Unique product ID for batch
|
| 157 |
'Product_Weight': float(item['Product_Weight']),
|
| 158 |
'Product_Sugar_Content': str(item['Product_Sugar_Content']),
|
| 159 |
'Product_Allocated_Area': float(item['Product_Allocated_Area']),
|
| 160 |
'Product_Type': str(item['Product_Type']),
|
| 161 |
'Product_MRP': float(item['Product_MRP']),
|
| 162 |
+
'Store_Id': f'OUT{i+1:03d}', # Unique store ID for batch
|
| 163 |
'Store_Establishment_Year': int(item['Store_Establishment_Year']),
|
| 164 |
'Store_Size': str(item['Store_Size']),
|
| 165 |
'Store_Location_City_Type': str(item['Store_Location_City_Type']),
|
| 166 |
+
'Store_Type': str(item['Store_Type']),
|
| 167 |
+
'Store_Age': store_age,
|
| 168 |
+
'Price_Efficiency': price_efficiency
|
| 169 |
}])
|
| 170 |
|
| 171 |
prediction = model.predict(input_data)[0]
|