Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files
app.py
CHANGED
|
@@ -73,27 +73,32 @@ def sales_price_batch():
|
|
| 73 |
file = request.files['file']
|
| 74 |
|
| 75 |
# Read the CSV file into a Pandas DataFrame
|
| 76 |
-
|
| 77 |
-
|
| 78 |
|
| 79 |
-
product_ids =
|
| 80 |
-
store_ids =
|
| 81 |
-
|
| 82 |
|
| 83 |
# Apply same transformations
|
| 84 |
#input_transformed = preprocessor.transform(input_data)
|
| 85 |
|
| 86 |
# Make predictions for all properties in the DataFrame (get log_prices)
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
predicted_sales = round(float(
|
| 91 |
-
|
| 92 |
-
#
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
|
| 98 |
# Run the Flask application in debug mode if this script is executed directly
|
| 99 |
if __name__ == '__main__':
|
|
|
|
| 73 |
file = request.files['file']
|
| 74 |
|
| 75 |
# Read the CSV file into a Pandas DataFrame
|
| 76 |
+
input_data_batch = pd.read_csv(file)
|
| 77 |
+
input_data_batch['Store_Age'] = 2025 - input_data_batch['Store_Establishment_Year']
|
| 78 |
|
| 79 |
+
product_ids = input_data_batch['Product_Id'].tolist() # Assuming 'Id' is the product ID column
|
| 80 |
+
store_ids = input_data_batch['Store_Id'].tolist() # Assuming 'Id' is the store ID column
|
| 81 |
+
input_data_batch = input_data_batch.drop(['Product_Id', 'Store_Id', 'Store_Establishment_Year'], axis=1)
|
| 82 |
|
| 83 |
# Apply same transformations
|
| 84 |
#input_transformed = preprocessor.transform(input_data)
|
| 85 |
|
| 86 |
# Make predictions for all properties in the DataFrame (get log_prices)
|
| 87 |
+
predictions = model.predict(input_data_batch).tolist()
|
| 88 |
+
|
| 89 |
+
# Round predictions
|
| 90 |
+
predicted_sales = [round(float(x), 2) for x in predictions]
|
| 91 |
+
|
| 92 |
+
# Structure output as a list of dicts
|
| 93 |
+
output_dict = [
|
| 94 |
+
{
|
| 95 |
+
"Product_Id": pid,
|
| 96 |
+
"Store_Id": sid,
|
| 97 |
+
"Predicted_Sales": psale
|
| 98 |
+
}
|
| 99 |
+
for pid, sid, psale in zip(product_ids, store_ids, predicted_sales)
|
| 100 |
+
]
|
| 101 |
+
return jsonify({"predictions": output_dict})
|
| 102 |
|
| 103 |
# Run the Flask application in debug mode if this script is executed directly
|
| 104 |
if __name__ == '__main__':
|