RavindraDubey12 commited on
Commit
1987345
·
verified ·
1 Parent(s): 475720c

Upload folder using huggingface_hub

Browse files
Files changed (4) hide show
  1. Dockerfile +16 -0
  2. app.py +59 -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,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import joblib
2
+ import numpy as np
3
+ import pandas as pd
4
+ import streamlit as st
5
+ from flask import Flask, request, jsonify
6
+ super_kart_api=Flask("Superkart_price_prediction")
7
+ model=joblib.load('model.joblib')
8
+ @super_kart_api.get('/')
9
+ def home():
10
+ return "Welcome to SuperKart sales Prediction"
11
+ @super_kart_api.post('/v1/spkart_single')
12
+ def sale_pred_single():
13
+ sale_data=request.get_json()
14
+ # Read input data
15
+ sample={
16
+ 'Product_Weight':sale_data['Product_Weight'],
17
+ 'Product_Sugar_Content':sale_data['Product_Sugar_Content'],
18
+ 'Product_Allocated_Area':sale_data['Product_Allocated_Area'],
19
+ 'Product_Type':sale_data['Product_Type'],
20
+ 'Product_MRP':sale_data['Product_MRP'],
21
+ 'Store_Id':sale_data['Store_Id'],
22
+ 'Store_Establishment_Year':sale_data['Store_Establishment_Year'],
23
+ 'Store_Size':sale_data['Store_Size'],
24
+ 'Store_Location_City_Type':sale_data['Store_Location_City_Type'],
25
+ 'Store_Type':sale_data['Store_Type'],
26
+
27
+ }
28
+ input_data=pd.DataFrame([sample])
29
+ # Make predictions
30
+ predicted_sale=model.predict(input_data)[0]
31
+ # Create response
32
+ response={'Store_Outlet':sample['Store_Id'],"Sale":round(float(predicted_sale), 2)}
33
+ return jsonify(response)
34
+
35
+ @super_kart_api.post('/v1/spkart_batch')
36
+ def sale_pred_batch():
37
+ file = request.files['file']
38
+ print("File Received:", file.filename)
39
+ # Read input data
40
+ input_data = pd.read_csv(file)
41
+ # Make predictions
42
+ predicted_sale = model.predict(input_data).tolist()
43
+ # Add predictions to input data
44
+ input_data['Predicted_Sale'] = predicted_sale
45
+ # Group by Store_Id and sum the predicted sales
46
+ grouped_sales = input_data.groupby('Store_Id')['Predicted_Sale'].sum().to_dict()
47
+ # Create response
48
+ response = {
49
+ 'store_sales': {store_id: round(float(sale), 2) for store_id, sale in grouped_sales.items()}
50
+ }
51
+ print("Final Response:", response)
52
+
53
+ return jsonify(response)
54
+
55
+
56
+
57
+
58
+ if __name__=='__main__':
59
+ 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.43.2