JohnsonSAimlarge commited on
Commit
f71eaf9
·
verified ·
1 Parent(s): 02cf7d0

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. Dockerfile +15 -12
  2. app.py +124 -0
  3. requirements.txt +7 -3
Dockerfile CHANGED
@@ -1,20 +1,23 @@
1
- FROM python:3.13.5-slim
 
2
 
 
3
  WORKDIR /app
4
 
5
- RUN apt-get update && apt-get install -y \
6
- build-essential \
7
- curl \
8
- git \
9
- && rm -rf /var/lib/apt/lists/*
10
-
11
- COPY requirements.txt ./
12
- COPY src/ ./src/
13
 
 
14
  RUN pip3 install -r requirements.txt
15
 
16
- EXPOSE 8501
 
 
 
 
 
17
 
18
- HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
19
 
20
- ENTRYPOINT ["streamlit", "run", "src/streamlit_app.py", "--server.port=8501", "--server.address=0.0.0.0"]
 
 
1
+ # Use a minimal base image with Python 3.9 installed
2
+ FROM python:3.9
3
 
4
+ # Set the working directory inside the container to /app
5
  WORKDIR /app
6
 
7
+ # Copy all files from the current directory on the host to the container's /app directory
8
+ COPY . .
 
 
 
 
 
 
9
 
10
+ # Install Python dependencies listed in requirements.txt
11
  RUN pip3 install -r requirements.txt
12
 
13
+ RUN useradd -m -u 1000 user
14
+ USER user
15
+ ENV HOME=/home/user \
16
+ PATH=/home/user/.local/bin:$PATH
17
+
18
+ WORKDIR $HOME/app
19
 
20
+ COPY --chown=user . $HOME/app
21
 
22
+ # Define the command to run the Streamlit app on port "8501" and make it accessible externally
23
+ CMD ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0", "--server.enableXsrfProtection=false"]
app.py ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import requests
3
+ import pandas as pd
4
+ import numpy as np
5
+
6
+ st.title("SuperKart Sales Prediction")
7
+
8
+ st.write("Enter the product and store details to get a sales prediction.")
9
+
10
+ # Input fields for product and store details
11
+ product_id = st.text_input("Product ID")
12
+ product_weight = st.number_input("Product Weight", min_value=0.0)
13
+ product_sugar_content = st.selectbox("Product Sugar Content", ['Low Sugar', 'Regular', 'No Sugar', 'reg'])
14
+ product_allocated_area = st.number_input("Product Allocated Area", min_value=0.0)
15
+ product_type = st.selectbox("Product Type", ['Frozen Foods', 'Dairy', 'Canned', 'Baking Goods', 'Health and Hygiene', 'Snack Foods', 'Household', 'Soft Drinks', 'Breads', 'Hard Drinks', 'Others', 'Starchy Foods', 'Breakfast', 'Seafood', 'Meat', 'Fruits and Vegetables'])
16
+ product_mrp = st.number_input("Product MRP", min_value=0.0)
17
+ store_id = st.selectbox("Store ID", ['OUT004', 'OUT003', 'OUT001', 'OUT002']) # Based on unique values from EDA
18
+ store_establishment_year = st.selectbox("Store Establishment Year", [1987, 1998, 1999, 2009]) # Based on unique values from EDA
19
+ store_size = st.selectbox("Store Size", ['Medium', 'High', 'Small'])
20
+ store_location_city_type = st.selectbox("Store Location City Type", ['Tier 2', 'Tier 1', 'Tier 3'])
21
+ store_type = st.selectbox("Store Type", ['Supermarket Type2', 'Departmental Store', 'Supermarket Type1', 'Food Mart'])
22
+
23
+
24
+ # Create a dictionary with the input data
25
+ data = {
26
+ 'Product_Id': [product_id],
27
+ 'Product_Weight': [product_weight],
28
+ 'Product_Sugar_Content': [product_sugar_content],
29
+ 'Product_Allocated_Area': [product_allocated_area],
30
+ 'Product_Type': [product_type],
31
+ 'Product_MRP': [product_mrp],
32
+ 'Store_Id': [store_id],
33
+ 'Store_Establishment_Year': [store_establishment_year],
34
+ 'Store_Size': [store_size],
35
+ 'Store_Location_City_Type': [store_location_city_type],
36
+ 'Store_Type': [store_type]
37
+ }
38
+
39
+ # Convert the dictionary to a pandas DataFrame
40
+ input_df = pd.DataFrame(data)
41
+
42
+ # Button to trigger prediction
43
+ if st.button("Predict Sales"):
44
+
45
+ api_url = "https://hellohatim-superkart-sales-prediction-backend.hf.space//predict"
46
+
47
+ try:
48
+ response = requests.post(api_url, json=input_df.to_dict(orient='records'))
49
+
50
+ if response.status_code == 200:
51
+ predictions = response.json()
52
+ st.success(f"Predicted Sales Total: {predictions[0]:.2f}")
53
+ else:
54
+ st.error(f"Error predicting sales: {response.status_code} - {response.text}")
55
+ except Exception as e:
56
+ st.error(f"An error occurred: {e}")
57
+
58
+
59
+ if st.button("Predict"):
60
+ prediction = model.predict(input_df)[0]
61
+ probability = model.predict_proba(input_df)[0][1]
62
+ st.success(f"✅ Predicted Sales Total: (Confidence: {probability:.2f})")
63
+
64
+
65
+
66
+ import streamlit as st
67
+ import pandas as pd
68
+ from huggingface_hub import hf_hub_download
69
+ import joblib
70
+
71
+ # Download and load the model
72
+ model_path = hf_hub_download(repo_id="JohnsonSAimlarge/superkart-prediction", filename="best_superkart_model_v1.joblib")
73
+ model = joblib.load(model_path)
74
+
75
+ # ------------------------------
76
+ # Streamlit UI
77
+ # ------------------------------
78
+ st.title("""Superkart""" + " - Sales Prediction ""superkart sales Prediction App")
79
+
80
+ st.write("""
81
+ This application predicts potential sales for superkart.
82
+ """)
83
+
84
+
85
+ # Input fields for product and store details
86
+ product_id = st.text_input("Product ID")
87
+ product_weight = st.number_input("Product Weight", min_value=0.0)
88
+ product_sugar_content = st.selectbox("Product Sugar Content", ['Low Sugar', 'Regular', 'No Sugar', 'reg'])
89
+ product_allocated_area = st.number_input("Product Allocated Area", min_value=0.0)
90
+ product_type = st.selectbox("Product Type", ['Frozen Foods', 'Dairy', 'Canned', 'Baking Goods', 'Health and Hygiene', 'Snack Foods', 'Household', 'Soft Drinks', 'Breads', 'Hard Drinks', 'Others', 'Starchy Foods', 'Breakfast', 'Seafood', 'Meat', 'Fruits and Vegetables'])
91
+ product_mrp = st.number_input("Product MRP", min_value=0.0)
92
+ store_id = st.selectbox("Store ID", ['OUT004', 'OUT003', 'OUT001', 'OUT002']) # Based on unique values from EDA
93
+ store_establishment_year = st.selectbox("Store Establishment Year", [1987, 1998, 1999, 2009]) # Based on unique values from EDA
94
+ store_size = st.selectbox("Store Size", ['Medium', 'High', 'Small'])
95
+ store_location_city_type = st.selectbox("Store Location City Type", ['Tier 2', 'Tier 1', 'Tier 3'])
96
+ store_type = st.selectbox("Store Type", ['Supermarket Type2', 'Departmental Store', 'Supermarket Type1', 'Food Mart'])
97
+
98
+
99
+ # Create a dictionary with the input data
100
+ data = {
101
+ 'Product_Id': [product_id],
102
+ 'Product_Weight': [product_weight],
103
+ 'Product_Sugar_Content': [product_sugar_content],
104
+ 'Product_Allocated_Area': [product_allocated_area],
105
+ 'Product_Type': [product_type],
106
+ 'Product_MRP': [product_mrp],
107
+ 'Store_Id': [store_id],
108
+ 'Store_Establishment_Year': [store_establishment_year],
109
+ 'Store_Size': [store_size],
110
+ 'Store_Location_City_Type': [store_location_city_type],
111
+ 'Store_Type': [store_type]
112
+ }
113
+
114
+
115
+ input_df = pd.DataFrame([input_data])
116
+
117
+ # ------------------------------
118
+ # Prediction
119
+ # ------------------------------
120
+
121
+ if st.button("Predict"):
122
+ prediction = model.predict(input_df)[0]
123
+ probability = model.predict_proba(input_df)[0][1]
124
+ st.success(f"✅ Predicted Sales Total: (Confidence: {probability:.2f})")
requirements.txt CHANGED
@@ -1,3 +1,7 @@
1
- altair
2
- pandas
3
- streamlit
 
 
 
 
 
1
+ pandas==2.2.2
2
+ huggingface_hub==0.32.6
3
+ streamlit==1.43.2
4
+ joblib==1.5.1
5
+ scikit-learn==1.6.0
6
+ xgboost==2.1.4
7
+ mlflow==3.0.1