Spaces:
Sleeping
Sleeping
Force upload app.py - 1754761163
Browse files
app.py
CHANGED
|
@@ -34,8 +34,23 @@ def home():
|
|
| 34 |
def predict_sales():
|
| 35 |
try:
|
| 36 |
data = request.get_json()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
input_df = pd.DataFrame([data])
|
| 38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
# Scale the input data (essential for correct predictions)
|
| 40 |
input_scaled = scaler.transform(input_df)
|
| 41 |
prediction = model.predict(input_scaled)
|
|
|
|
| 34 |
def predict_sales():
|
| 35 |
try:
|
| 36 |
data = request.get_json()
|
| 37 |
+
|
| 38 |
+
# Calculate Store_Age from Store_Establishment_Year (as done in training)
|
| 39 |
+
current_year = 2025 # Use consistent year as in training
|
| 40 |
+
if 'Store_Establishment_Year' in data:
|
| 41 |
+
data['Store_Age'] = current_year - data['Store_Establishment_Year']
|
| 42 |
+
del data['Store_Establishment_Year'] # Remove original field
|
| 43 |
+
|
| 44 |
input_df = pd.DataFrame([data])
|
| 45 |
|
| 46 |
+
# Ensure columns are in the same order as training
|
| 47 |
+
expected_columns = ['Product_Weight', 'Product_MRP', 'Product_Sugar_Content',
|
| 48 |
+
'Product_Type', 'Store_Id', 'Store_Size',
|
| 49 |
+
'Store_Location_City_Type', 'Store_Type', 'Store_Age']
|
| 50 |
+
|
| 51 |
+
# Reorder columns to match training data
|
| 52 |
+
input_df = input_df.reindex(columns=expected_columns)
|
| 53 |
+
|
| 54 |
# Scale the input data (essential for correct predictions)
|
| 55 |
input_scaled = scaler.transform(input_df)
|
| 56 |
prediction = model.predict(input_scaled)
|