dev02chandan commited on
Commit
adf391d
·
verified ·
1 Parent(s): f0b28b8

Upload app/streamlit_app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app/streamlit_app.py +61 -0
app/streamlit_app.py ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import pandas as pd
3
+ import numpy as np
4
+ import streamlit as st
5
+ import joblib
6
+ from huggingface_hub import hf_hub_download
7
+
8
+ # Model repo (overridable via env)
9
+ MODEL_REPO = os.getenv("MODEL_ID", "dev02chandan/sales-forecast-model")
10
+
11
+ @st.cache_resource
12
+ def load_model():
13
+ pkl_path = hf_hub_download(repo_id=MODEL_REPO, repo_type="model", filename="model.pkl")
14
+ return joblib.load(pkl_path)
15
+
16
+ model = load_model()
17
+
18
+ st.title("Sales Forecast: Product × Store")
19
+
20
+ # Inputs
21
+ with st.form("inference"):
22
+ col1, col2 = st.columns(2)
23
+ with col1:
24
+ product_id = st.text_input("Product_Id", "FD30")
25
+ product_weight = st.number_input("Product_Weight", min_value=0.0, value=500.0)
26
+ sugar = st.selectbox("Product_Sugar_Content", ["low sugar","regular","no sugar"])
27
+ allocated_area = st.number_input("Product_Allocated_Area", min_value=0.0, max_value=1.0, value=0.05)
28
+ product_type = st.text_input("Product_Type", "dairy")
29
+ with col2:
30
+ product_mrp = st.number_input("Product_MRP", min_value=0.0, value=199.0)
31
+ store_id = st.text_input("Store_Id", "OUT001")
32
+ store_est_year = st.number_input("Store_Establishment_Year", min_value=1900, max_value=2100, value=2010)
33
+ store_size = st.selectbox("Store_Size", ["Small","Medium","High"])
34
+ city_type = st.selectbox("Store_Location_City_Type", ["Tier 1","Tier 2","Tier 3"])
35
+ store_type = st.selectbox("Store_Type", ["Departmental Store","Supermarket Type1","Supermarket Type2","Food Mart"])
36
+ submitted = st.form_submit_button("Predict")
37
+
38
+ if submitted:
39
+ # Engineered features used during training
40
+ store_age = max(0, 2025 - int(store_est_year))
41
+ mrp_x_area = float(product_mrp) * float(allocated_area)
42
+
43
+ # Assemble frame in the same schema as training
44
+ row = {
45
+ "Product_Id": product_id,
46
+ "Product_Sugar_Content": sugar,
47
+ "Product_Type": product_type,
48
+ "Store_Id": store_id,
49
+ "Store_Size": store_size,
50
+ "Store_Location_City_Type": city_type,
51
+ "Store_Type": store_type,
52
+ "Product_Weight": float(product_weight),
53
+ "Product_Allocated_Area": float(allocated_area),
54
+ "Product_MRP": float(product_mrp),
55
+ "Store_Establishment_Year": int(store_est_year),
56
+ "Store_Age": float(store_age),
57
+ "MRP_x_Area": float(mrp_x_area),
58
+ }
59
+ X = pd.DataFrame([row])
60
+ y_pred = model.predict(X)[0]
61
+ st.metric("Predicted Product_Store_Sales_Total", f"{y_pred:,.2f}")