Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- Dockerfile +7 -0
- app.py +1 -51
Dockerfile
CHANGED
|
@@ -10,6 +10,13 @@ COPY . .
|
|
| 10 |
RUN pip install --upgrade pip
|
| 11 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
# expose port (Spaces listens on 7860)
|
| 14 |
ENV PORT=7860
|
| 15 |
EXPOSE 7860
|
|
|
|
| 10 |
RUN pip install --upgrade pip
|
| 11 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 12 |
|
| 13 |
+
# Verify model file exists
|
| 14 |
+
RUN if [ ! -f "superkart_sales_forecast_model_v1_1.joblib" ]; then \
|
| 15 |
+
echo "❌ Model file not found!" && exit 1; \
|
| 16 |
+
else \
|
| 17 |
+
echo "✅ Model file exists, proceeding"; \
|
| 18 |
+
fi
|
| 19 |
+
|
| 20 |
# expose port (Spaces listens on 7860)
|
| 21 |
ENV PORT=7860
|
| 22 |
EXPOSE 7860
|
app.py
CHANGED
|
@@ -1,54 +1,4 @@
|
|
| 1 |
|
| 2 |
-
# backend_files/app.py
|
| 3 |
-
import numpy as np
|
| 4 |
-
import pandas as pd
|
| 5 |
-
import joblib
|
| 6 |
-
from flask import Flask, request, jsonify
|
| 7 |
-
|
| 8 |
-
# initiate flask application
|
| 9 |
-
app = Flask("SuperKart Sales Price Prediction API")
|
| 10 |
-
|
| 11 |
-
# Load the trained model (ensure file exists in the correct path)
|
| 12 |
-
model = joblib.load("superkart_prediction.joblib")
|
| 13 |
-
|
| 14 |
-
# HOME ROUTE
|
| 15 |
-
@app.route("/", methods=["GET"])
|
| 16 |
-
def home():
|
| 17 |
-
return "Welcome to the SuperKart Sales Prediction API!"
|
| 18 |
-
|
| 19 |
-
# SINGLE SALES PREDICTION
|
| 20 |
-
@app.route("/v1/sales", methods=["POST"])
|
| 21 |
-
def predict_sales_single():
|
| 22 |
-
try:
|
| 23 |
-
sales_data = request.get_json(force=True)
|
| 24 |
-
sample = {
|
| 25 |
-
'Product_Id': sales_data.get('Product_Id'),
|
| 26 |
-
'Product_Weight': sales_data.get('Product_Weight'),
|
| 27 |
-
'Product_Sugar_Content': sales_data.get('Product_Sugar_Content'),
|
| 28 |
-
'Product_Allocated_Area': sales_data.get('Product_Allocated_Area'),
|
| 29 |
-
'Product_Type': sales_data.get('Product_Type'),
|
| 30 |
-
'Product_MRP': sales_data.get('Product_MRP'),
|
| 31 |
-
'Store_Id': sales_data.get('Store_Id'),
|
| 32 |
-
'Store_Establishment_Year': sales_data.get('Store_Establishment_Year'),
|
| 33 |
-
'Store_Size': sales_data.get('Store_Size'),
|
| 34 |
-
'Store_Location_City_Type': sales_data.get('Store_Location_City_Type'),
|
| 35 |
-
'Store_Type': sales_data.get('Store_Type')
|
| 36 |
-
}
|
| 37 |
-
input_df = pd.DataFrame([sample])
|
| 38 |
-
log_pred = model.predict(input_df)[0]
|
| 39 |
-
predicted_sale = round(float(np.exp(log_pred)), 2)
|
| 40 |
-
return jsonify({"predicted_sales_in_dollars": predicted_sale}), 200
|
| 41 |
-
except Exception as e:
|
| 42 |
-
return jsonify({"error": str(e)}), 400
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
# Main runner for local testing (not used by Gunicorn)
|
| 47 |
-
if __name__ == "__main__":
|
| 48 |
-
app.run(host="0.0.0.0", port=7860, debug=True)
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
|
| 53 |
import numpy as np
|
| 54 |
import joblib
|
|
@@ -120,7 +70,7 @@ def predict_sales():
|
|
| 120 |
except Exception as e:
|
| 121 |
print("❌ Error during prediction:", str(e))
|
| 122 |
return jsonify({'error': f"Prediction failed: {str(e)}"}), 500
|
| 123 |
-
|
| 124 |
# BATCH SALES PREDICTION
|
| 125 |
@app.route("/v1/sales_batch", methods=["POST"])
|
| 126 |
def predict_sales_batch():
|
|
|
|
| 1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
import numpy as np
|
| 4 |
import joblib
|
|
|
|
| 70 |
except Exception as e:
|
| 71 |
print("❌ Error during prediction:", str(e))
|
| 72 |
return jsonify({'error': f"Prediction failed: {str(e)}"}), 500
|
| 73 |
+
|
| 74 |
# BATCH SALES PREDICTION
|
| 75 |
@app.route("/v1/sales_batch", methods=["POST"])
|
| 76 |
def predict_sales_batch():
|