Hunagypsy commited on
Commit
316153b
·
verified ·
1 Parent(s): 3ba4a7f

Upload 4 files

Browse files
Dockerfile ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.9-slim
2
+
3
+ WORKDIR /app
4
+ COPY . .
5
+
6
+ RUN apt-get update && apt-get install -y \
7
+ build-essential \
8
+ curl \
9
+ git \
10
+ && rm -rf /var/lib/apt/lists/*
11
+
12
+ RUN pip install --no-cache-dir -r requirements.txt
13
+
14
+ EXPOSE 7860
15
+ CMD ["gunicorn", "-w", "2", "-b", "0.0.0.0:7860", "app:superkart_api"]
app.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ import joblib
3
+ from flask import Flask, request, jsonify
4
+ import os # Import os for debugging
5
+
6
+ superkart_api = Flask(__name__)
7
+
8
+ print("--- APP STARTUP: Flask app instance created ---")
9
+
10
+ # Load the trained model
11
+ try:
12
+ print(f"--- APP STARTUP: Attempting to load model from {os.path.join(os.getcwd(), MODEL_FILENAME)} ---")
13
+ model = joblib.load("tuned_gradient_boosting_regressor_model.joblib")
14
+ print("--- APP STARTUP: Model loaded successfully ---")
15
+ except Exception as e:
16
+ print(f"--- APP STARTUP: ERROR loading model: {e} ---")
17
+ raise # Re-raise to crash early if model loading fails
18
+
19
+ print("--- APP STARTUP: Model variable assigned ---")
20
+
21
+ @superkart_api.get('/')
22
+ def home():
23
+ print("--- REQUEST: Home endpoint accessed ---")
24
+ return "Welcome to the Superkart Sales Prediction API!"
25
+
26
+ @superkart_api.post('/v1/predict')
27
+ def predict_sales():
28
+ print("--- REQUEST: Predict endpoint accessed ---")
29
+ data = request.get_json()
30
+ # ... (rest of your predict_sales logic) ...
31
+ sample = {
32
+ 'Product_Weight': data['Product_Weight'],
33
+ 'Product_Sugar_Content': data['Product_Sugar_Content'],
34
+ 'Product_Allocated_Area': data['Product_Allocated_Area'],
35
+ 'Product_MRP': data['Product_MRP'],
36
+ 'Store_Size': data['Store_Size'],
37
+ 'Store_Location_City_Type': data['Store_Location_City_Type'],
38
+ 'Store_Type': data['Store_Type'],
39
+ 'Product_Id_char': data['Product_Id_char'],
40
+ 'Store_Age_Years': data['Store_Age_Years'],
41
+ 'Product_Type_Category': data['Product_Type_Category']
42
+ }
43
+ input_df = pd.DataFrame([sample])
44
+ prediction = model.predict(input_df).tolist()[0]
45
+ print(f"--- REQUEST: Prediction made: {prediction} ---")
46
+ return jsonify({'Sales': prediction})
47
+
48
+ if __name__ == '__main__':
49
+ print("--- APP STARTUP: Running in __main__ block ---")
50
+ # import os # Redundant import removed
51
+ port = int(os.environ.get("PORT", 7860))
52
+ superkart_api.run(host="0.0.0.0", port=port)
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ pandas==2.2.2
2
+ numpy==2.0.2
3
+ scikit-learn==1.6.1
4
+ xgboost==2.1.4
5
+ joblib==1.4.2
6
+ flask==3.0.3 # <-- CHANGED TO 3.0.3
7
+ gunicorn==20.1.0
tuned_gradient_boosting_regressor_model.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:42fa408c73255e88dad17d07e822e9d9896c8dae68ba8786af1d9eced3abcce7
3
+ size 196171