Spaces:
Paused
Paused
Upload folder using huggingface_hub
Browse files- Dockerfile +0 -2
- SuperKart_prediction_model_v1_0.joblib +2 -2
- app.py +51 -42
- requirements.txt +11 -1
Dockerfile
CHANGED
|
@@ -12,5 +12,3 @@ RUN pip3 install -r requirements.txt
|
|
| 12 |
|
| 13 |
# Define the command to run the Streamlit app on port 8501 and make it accessible externally
|
| 14 |
CMD ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0", "--server.enableXsrfProtection=false"]
|
| 15 |
-
|
| 16 |
-
# NOTE: Disable XSRF protection for easier external access in order to make batch predictions
|
|
|
|
| 12 |
|
| 13 |
# Define the command to run the Streamlit app on port 8501 and make it accessible externally
|
| 14 |
CMD ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0", "--server.enableXsrfProtection=false"]
|
|
|
|
|
|
SuperKart_prediction_model_v1_0.joblib
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:3af9691e3fe153ab300bdca3d9c252d7f6093bf233d4fab7302ff16a9b9d999d
|
| 3 |
+
size 325355
|
app.py
CHANGED
|
@@ -1,11 +1,18 @@
|
|
| 1 |
-
|
| 2 |
import streamlit as st
|
| 3 |
import pandas as pd
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
-
|
| 6 |
|
| 7 |
-
#
|
| 8 |
-
st.
|
|
|
|
| 9 |
|
| 10 |
# Input fields for product and store data based on SuperKart dataset features
|
| 11 |
product_weight = st.number_input("Product Weight", min_value=0.0, value=12.66)
|
|
@@ -19,43 +26,45 @@ store_size = st.selectbox("Store Size", ["Small", "Medium", "High"])
|
|
| 19 |
store_location_city_type = st.selectbox("Store Location City Type", ["Tier 1", "Tier 2", "Tier 3"])
|
| 20 |
store_type = st.selectbox("Store Type", ["Departmental Store", "Supermarket Type1", "Supermarket Type2", "Food Mart"])
|
| 21 |
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
'
|
| 25 |
-
'
|
| 26 |
-
'
|
| 27 |
-
'
|
| 28 |
-
'
|
| 29 |
-
'
|
| 30 |
-
'
|
| 31 |
-
'
|
| 32 |
-
'
|
|
|
|
| 33 |
}
|
| 34 |
|
| 35 |
-
#
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
|
|
|
|
|
| 1 |
+
|
| 2 |
import streamlit as st
|
| 3 |
import pandas as pd
|
| 4 |
+
from datetime import datetime
|
| 5 |
+
import joblib
|
| 6 |
+
|
| 7 |
+
# Load the trained model
|
| 8 |
+
def load_model():
|
| 9 |
+
return joblib.load("SuperKart_sales_prediction_model_v1_0.joblib")
|
| 10 |
|
| 11 |
+
model = load_model()
|
| 12 |
|
| 13 |
+
# Streamlit UI for Customer Churn Prediction
|
| 14 |
+
st.title("Sales Prediction App")
|
| 15 |
+
st.write("This tool predicts customer Sales details. Enter the required information below.")
|
| 16 |
|
| 17 |
# Input fields for product and store data based on SuperKart dataset features
|
| 18 |
product_weight = st.number_input("Product Weight", min_value=0.0, value=12.66)
|
|
|
|
| 26 |
store_location_city_type = st.selectbox("Store Location City Type", ["Tier 1", "Tier 2", "Tier 3"])
|
| 27 |
store_type = st.selectbox("Store Type", ["Departmental Store", "Supermarket Type1", "Supermarket Type2", "Food Mart"])
|
| 28 |
|
| 29 |
+
# Convert categorical inputs to match model training
|
| 30 |
+
input_data = {
|
| 31 |
+
'Product_Weight': [product_weight],
|
| 32 |
+
'Product_Sugar_Content': [product_sugar_content],
|
| 33 |
+
'Product_Allocated_Area': [product_allocated_area],
|
| 34 |
+
'Product_Type': [product_type],
|
| 35 |
+
'Product_MRP': [product_mrp],
|
| 36 |
+
'Store_Id': [store_id],
|
| 37 |
+
'Store_Establishment_Year': [store_establishment_year],
|
| 38 |
+
'Store_Size': [store_size],
|
| 39 |
+
'Store_Location_City_Type': [store_location_city_type],
|
| 40 |
+
'Store_Type': [store_type],
|
| 41 |
}
|
| 42 |
|
| 43 |
+
# Custom transformer to calculate store age
|
| 44 |
+
class StoreAgeCalculator(BaseEstimator, TransformerMixin):
|
| 45 |
+
def __init__(self):
|
| 46 |
+
self.current_year = datetime.now().year
|
| 47 |
+
|
| 48 |
+
def fit(self, X, y=None):
|
| 49 |
+
return self
|
| 50 |
+
|
| 51 |
+
def transform(self, X):
|
| 52 |
+
X = X.copy()
|
| 53 |
+
X['Store_Age'] = self.current_year - X['Store_Establishment_Year']
|
| 54 |
+
return X.drop(columns=['Store_Establishment_Year'])
|
| 55 |
+
|
| 56 |
+
# Convert the input data to a DataFrame
|
| 57 |
+
input_df = pd.DataFrame(input_data)
|
| 58 |
+
|
| 59 |
+
# Convert categorical columns to category type
|
| 60 |
+
input_df['Product_Sugar_Content'] = input_df['Product_Sugar_Content'].astype('category')
|
| 61 |
+
input_df['Product_Type'] = input_df['Product_Type'].astype('category')
|
| 62 |
+
input_df['Store_Id'] = input_df['Store_Id'].astype('category')
|
| 63 |
+
input_df['Store_Size'] = input_df['Store_Size'].astype('category')
|
| 64 |
+
input_df['Store_Location_City_Type'] = input_df['Store_Location_City_Type'].astype('category')
|
| 65 |
+
input_df['Store_Type'] = input_df['Store_Type'].astype('category')
|
| 66 |
+
|
| 67 |
+
# Make predictions
|
| 68 |
+
if st.button("Predict"):
|
| 69 |
+
predictions = model.predict(input_df)
|
| 70 |
+
st.write(f"Prediction: The customer is likely to **{predictions[0]}**.")
|
requirements.txt
CHANGED
|
@@ -1,3 +1,13 @@
|
|
| 1 |
pandas==2.2.2
|
| 2 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
streamlit==1.43.2
|
|
|
|
|
|
|
|
|
| 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 |
+
Werkzeug==2.2.2
|
| 7 |
+
flask==2.2.2
|
| 8 |
+
gunicorn==20.1.0
|
| 9 |
+
requests==2.32.3
|
| 10 |
+
uvicorn[standard]
|
| 11 |
streamlit==1.43.2
|
| 12 |
+
huggingface_hub==0.30.1
|
| 13 |
+
seaborn==0.13.2
|