ScottIzi commited on
Commit
244d09a
·
verified ·
1 Parent(s): f0bf3c1

Upload folder using huggingface_hub

Browse files
Dockerfile ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.9-slim
2
+
3
+ # Set the working directory inside the container
4
+ WORKDIR /app
5
+
6
+ # Copy all files from current directory to container
7
+ COPY . .
8
+
9
+ # Install dependencies
10
+ RUN pip install --no-cache-dir --upgrade -r requirements.txt
11
+
12
+ # Run Flask app with Gunicorn
13
+ CMD ["gunicorn", "-w", "4", "-b", "0.0.0.0:7860", "app:superkart_api"]
Gradient-Boosting-Regressor-Tuned.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c173a318702c4f688b645fcebdf75eb410a1dc4db64db148c83e7ae485123798
3
+ size 53708
app.py ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ # Import necessary libraries
3
+ import numpy as np
4
+ import joblib # For loading the serialized model
5
+ import polars as pl # Polars instead of pandas
6
+ from flask import Flask, request, jsonify # Flask API
7
+
8
+ # Initialize Flask app with a name
9
+ superkart_api = Flask("SuperKart_API")
10
+
11
+ # Load trained model pipeline
12
+ model = joblib.load("backend_files/Gradient-Boosting-Regressor-Tuned.joblib")
13
+
14
+ # Home route
15
+ @superkart_api.get('/')
16
+ def home():
17
+ return "SuperKart Sales Prediction API is running"
18
+
19
+ # Prediction endpoint
20
+ @superkart_api.post('/v1/predict')
21
+ def predict_sales():
22
+ # Get JSON input
23
+ data = request.get_json()
24
+
25
+ # Extract features
26
+ required_fields = [
27
+ 'Product_Weight',
28
+ 'Product_Sugar_Content',
29
+ 'Product_Allocated_Area',
30
+ 'Product_MRP',
31
+ 'Store_Size',
32
+ 'Store_Location_City_Type',
33
+ 'Store_Type',
34
+ 'Product_Id_char',
35
+ 'Store_Age_Years',
36
+ 'Product_Type_Category'
37
+ ]
38
+
39
+ # Check for missing or null values
40
+ missing_fields = [
41
+ field for field in required_fields
42
+ if field not in data or data[field] is None or data[field] == ""
43
+ ]
44
+
45
+ # If any field is missing → return error
46
+ if missing_fields:
47
+ return jsonify({
48
+ "error": "Missing or empty fields in request body",
49
+ "missing_fields": missing_fields,
50
+ "expected_format": {
51
+ "Product_Weight": "float",
52
+ "Product_Sugar_Content": "string",
53
+ "Product_Allocated_Area": "float",
54
+ "Product_MRP": "float",
55
+ "Store_Size": "string",
56
+ "Store_Location_City_Type": "string",
57
+ "Store_Type": "string",
58
+ "Product_Id_char": "string",
59
+ "Store_Age_Years": "float",
60
+ "Product_Type_Category": "string"
61
+ }
62
+ }), 400
63
+
64
+ # Safe to build sample
65
+ sample = {
66
+ 'Product_Weight': data['Product_Weight'],
67
+ 'Product_Sugar_Content': data['Product_Sugar_Content'],
68
+ 'Product_Allocated_Area': data['Product_Allocated_Area'],
69
+ 'Product_MRP': data['Product_MRP'],
70
+ 'Store_Size': data['Store_Size'],
71
+ 'Store_Location_City_Type': data['Store_Location_City_Type'],
72
+ 'Store_Type': data['Store_Type'],
73
+ 'Product_Id_char': data['Product_Id_char'],
74
+ 'Store_Age_Years': data['Store_Age_Years'],
75
+ 'Product_Type_Category': data['Product_Type_Category']
76
+ }
77
+
78
+ # Convert to Polars DataFrame
79
+ input_data = pl.DataFrame([sample])
80
+
81
+ # Convert to numpy for sklearn compatibility (safe step)
82
+ prediction = model.predict(input_data.to_pandas()).tolist()[0]
83
+
84
+ return jsonify({'Sales': prediction})
85
+
86
+
87
+ # Run app
88
+ if __name__ == '__main__':
89
+ superkart_api.run(debug=True)
requirements.txt ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ annotated-types==0.7.0
2
+ anyio==4.13.0
3
+ argon2-cffi==25.1.0
4
+ argon2-cffi-bindings==25.1.0
5
+ arrow==1.4.0
6
+ asttokens==3.0.1
7
+ async-lru==2.3.0
8
+ attrs==26.1.0
9
+ babel==2.18.0
10
+ beautifulsoup4==4.14.3
11
+ bleach==6.3.0
12
+ blinker==1.9.0
13
+ certifi==2026.4.22
14
+ cffi==2.0.0
15
+ charset-normalizer==3.4.7
16
+ click==8.3.3
17
+ comm==0.2.3
18
+ contourpy==1.3.3
19
+ cycler==0.12.1
20
+ dacite==1.9.2
21
+ debugpy==1.8.20
22
+ decorator==5.2.1
23
+ defusedxml==0.7.1
24
+ executing==2.2.1
25
+ fastjsonschema==2.21.2
26
+ fg-data-profiling==4.19.1
27
+ gunicorn==21.2.0