Upload folder using huggingface_hub
Browse files- Dockerfile +11 -9
- app.py +67 -52
- requirements.txt +6 -11
Dockerfile
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
|
|
|
|
|
| 1 |
FROM python:3.10-slim
|
| 2 |
|
| 3 |
-
# Set
|
| 4 |
WORKDIR /app
|
| 5 |
|
| 6 |
-
# Copy
|
| 7 |
COPY . .
|
| 8 |
|
| 9 |
-
# Install dependencies
|
| 10 |
-
RUN pip install --no-cache-dir -
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
-
#
|
| 13 |
-
|
| 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:t_sales_predictor_api"]
|
|
|
|
| 1 |
+
|
| 2 |
+
# Use the official Streamlit image
|
| 3 |
FROM python:3.10-slim
|
| 4 |
|
| 5 |
+
# Set working directory
|
| 6 |
WORKDIR /app
|
| 7 |
|
| 8 |
+
# Copy app files
|
| 9 |
COPY . .
|
| 10 |
|
| 11 |
+
# Install dependencies
|
| 12 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 13 |
+
|
| 14 |
+
# Expose Streamlit default port
|
| 15 |
+
EXPOSE 7860
|
| 16 |
|
| 17 |
+
# Run the Streamlit app
|
| 18 |
+
CMD ["streamlit", "run", "app.py", "--server.port=7860", "--server.enableCORS=false"]
|
|
|
|
|
|
|
|
|
app.py
CHANGED
|
@@ -1,53 +1,68 @@
|
|
| 1 |
-
import
|
| 2 |
-
import joblib
|
| 3 |
import pandas as pd
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
#
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
|
|
|
| 2 |
import pandas as pd
|
| 3 |
+
import joblib
|
| 4 |
+
|
| 5 |
+
# Load trained model
|
| 6 |
+
@st.cache_resource
|
| 7 |
+
def load_model():
|
| 8 |
+
return joblib.load("t_superkart_sales_prediction_model_v1_0.joblib")
|
| 9 |
+
|
| 10 |
+
model = load_model()
|
| 11 |
+
|
| 12 |
+
st.set_page_config(page_title="SuperKart Sales Predictor", layout="wide")
|
| 13 |
+
st.title("🛒 SuperKart Sales Prediction App")
|
| 14 |
+
|
| 15 |
+
st.write("Fill in the product and store details below to predict sales.")
|
| 16 |
+
|
| 17 |
+
# Input fields
|
| 18 |
+
col1, col2 = st.columns(2)
|
| 19 |
+
|
| 20 |
+
with col1:
|
| 21 |
+
product_weight = st.number_input("Product Weight", min_value=0.0, step=0.01)
|
| 22 |
+
product_allocated_area = st.number_input("Product Allocated Area", min_value=0.0, step=0.001)
|
| 23 |
+
product_mrp = st.number_input("Product MRP", min_value=0.0, step=0.01)
|
| 24 |
+
product_store_sales_total = st.number_input("Product Store Sales Total", min_value=0.0, step=0.01)
|
| 25 |
+
store_age = st.number_input("Store Age (Years)", min_value=0, step=1)
|
| 26 |
+
|
| 27 |
+
with col2:
|
| 28 |
+
product_sugar_content = st.selectbox("Sugar Content", ["no sugar", "regular"])
|
| 29 |
+
product_type = st.selectbox(
|
| 30 |
+
"Product Type",
|
| 31 |
+
["breads", "breakfast", "canned", "dairy", "frozen foods",
|
| 32 |
+
"fruits and vegetables", "hard drinks", "health and hygiene",
|
| 33 |
+
"household", "meat", "others", "seafood", "snack foods",
|
| 34 |
+
"soft drinks", "starchy foods"]
|
| 35 |
+
)
|
| 36 |
+
store_size = st.selectbox("Store Size", ["small", "medium"])
|
| 37 |
+
store_location_city_type = st.selectbox("Store Location City Type", ["tier 2", "tier 3"])
|
| 38 |
+
store_type = st.selectbox("Store Type", ["food mart", "supermarket type1", "supermarket type2"])
|
| 39 |
+
product_group_code = st.selectbox("Product Group Code", ["fd", "nc"])
|
| 40 |
+
|
| 41 |
+
# Convert inputs to DataFrame
|
| 42 |
+
input_data = {
|
| 43 |
+
"Product_Weight": product_weight,
|
| 44 |
+
"Product_Allocated_Area": product_allocated_area,
|
| 45 |
+
"Product_MRP": product_mrp,
|
| 46 |
+
"Product_Store_Sales_Total": product_store_sales_total,
|
| 47 |
+
"Store_Age": store_age,
|
| 48 |
+
f"Product_Sugar_Content_{product_sugar_content}": True,
|
| 49 |
+
f"Product_Type_{product_type}": True,
|
| 50 |
+
f"Store_Size_{store_size}": True,
|
| 51 |
+
f"Store_Location_City_Type_{store_location_city_type}": True,
|
| 52 |
+
f"Store_Type_{store_type}": True,
|
| 53 |
+
f"Product_Group_Code_{product_group_code}": True
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
input_df = pd.DataFrame([input_data]).astype(object)
|
| 57 |
+
|
| 58 |
+
# Align with model features
|
| 59 |
+
if hasattr(model, "feature_names_in_"):
|
| 60 |
+
input_df = input_df.reindex(columns=model.feature_names_in_, fill_value=0)
|
| 61 |
+
|
| 62 |
+
# Prediction
|
| 63 |
+
if st.button("Predict"):
|
| 64 |
+
try:
|
| 65 |
+
prediction = model.predict(input_df)[0]
|
| 66 |
+
st.success(f"Predicted Product Sales: {prediction:.2f}")
|
| 67 |
+
except Exception as e:
|
| 68 |
+
st.error(f"Prediction failed: {e}")
|
requirements.txt
CHANGED
|
@@ -1,11 +1,6 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
joblib
|
| 6 |
-
|
| 7 |
-
flask==2.2.2
|
| 8 |
-
gunicorn==20.1.0
|
| 9 |
-
requests==2.28.1
|
| 10 |
-
uvicorn[standard]
|
| 11 |
-
streamlit==1.43.2
|
|
|
|
| 1 |
+
streamlit
|
| 2 |
+
requests
|
| 3 |
+
pandas
|
| 4 |
+
scikit-learn
|
| 5 |
+
joblib
|
| 6 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|