Enoch1359 commited on
Commit
eabff23
·
verified ·
1 Parent(s): 9b7fb03

Upload folder using huggingface_hub

Browse files
Files changed (4) hide show
  1. Dockerfile +16 -0
  2. app.py +58 -0
  3. model.joblib +3 -0
  4. requirements.txt +10 -0
Dockerfile ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.9-slim
2
+
3
+ # Set the working directory inside the container
4
+ WORKDIR /app
5
+
6
+ # Copy all files from the current directory to the container's working directory
7
+ COPY . .
8
+
9
+ # Install dependencies from the requirements file without using cache to reduce image size
10
+ RUN pip install --no-cache-dir --upgrade -r requirements.txt
11
+
12
+ # Define the command to start the application using Gunicorn with 4 worker processes
13
+ # - `-w 4`: Uses 4 worker processes for handling requests
14
+ # - `-b 0.0.0.0:7860`: Binds the server to port 7860 on all network interfaces
15
+ # - `app:app`: Runs the Flask app (assuming `app.py` contains the Flask instance named `app`)
16
+ CMD ["gunicorn", "-w", "4", "-b", "0.0.0.0:7860", "app:super_kart_api"]
app.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import joblib
2
+ import numpy as np
3
+ import pandas as pd
4
+ from flask import Flask, request, jsonify
5
+ super_kart_api=Flask("Superkart_price_prediction")
6
+ model=joblib.load('model.joblib')
7
+ @super_kart_api.get('/')
8
+ def home():
9
+ return "Welcome to SuperKart sales Prediction"
10
+ @super_kart_api.post('/v1/spkart_single')
11
+ def sale_pred_single():
12
+ sale_data=request.get_json()
13
+ # Read input data
14
+ sample={
15
+ 'Product_Weight':sale_data['Product_Weight'],
16
+ 'Product_Sugar_Content':sale_data['Product_Sugar_Content'],
17
+ 'Product_Allocated_Area':sale_data['Product_Allocated_Area'],
18
+ 'Product_Type':sale_data['Product_Type'],
19
+ 'Product_MRP':sale_data['Product_MRP'],
20
+ 'Store_Id':sale_data['Store_Id'],
21
+ 'Store_Establishment_Year':sale_data['Store_Establishment_Year'],
22
+ 'Store_Size':sale_data['Store_Size'],
23
+ 'Store_Location_City_Type':sale_data['Store_Location_City_Type'],
24
+ 'Store_Type':sale_data['Store_Type'],
25
+
26
+ }
27
+ input_data=pd.DataFrame([sample])
28
+ # Make predictions
29
+ predicted_sale=model.predict(input_data)[0]
30
+ # Create response
31
+ response={'Store_Outlet':sample['Store_Id'],"Sale":round(float(predicted_sale), 2)}
32
+ return jsonify(response)
33
+
34
+ @super_kart_api.post('/v1/spkart_batch')
35
+ def sale_pred_batch():
36
+ file = request.files['file']
37
+ print("File Received:", file.filename)
38
+ # Read input data
39
+ input_data = pd.read_csv(file)
40
+ # Make predictions
41
+ predicted_sale = model.predict(input_data).tolist()
42
+ # Add predictions to input data
43
+ input_data['Predicted_Sale'] = predicted_sale
44
+ # Group by Store_Id and sum the predicted sales
45
+ grouped_sales = input_data.groupby('Store_Id')['Predicted_Sale'].sum().to_dict()
46
+ # Create response
47
+ response = {
48
+ 'store_sales': {store_id: round(float(sale), 2) for store_id, sale in grouped_sales.items()}
49
+ }
50
+ print("Final Response:", response)
51
+
52
+ return jsonify(response)
53
+
54
+
55
+
56
+
57
+ if __name__=='__main__':
58
+ super_kart_api.run()
model.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c3d1c3d09fff9f3a1613ee7fb4c57dac39befa10e9cd38925e2c3525a954e726
3
+ size 47878826
requirements.txt ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ pandas==2.2.2
2
+ numpy==2.0.2
3
+ scikit-learn==1.6.1
4
+ xgboost==2.1.4
5
+ joblib==1.5.1
6
+ Werkzeug==3.1.3
7
+ flask==3.1.1
8
+ gunicorn==23.0.0
9
+ requests==2.32.3
10
+ streamlit==1.46.1