File size: 2,479 Bytes
adf391d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
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
54
55
56
57
58
59
60
61
62
import os
import pandas as pd
import numpy as np
import streamlit as st
import joblib
from huggingface_hub import hf_hub_download

# Model repo (overridable via env)
MODEL_REPO = os.getenv("MODEL_ID", "dev02chandan/sales-forecast-model")

@st.cache_resource
def load_model():
    pkl_path = hf_hub_download(repo_id=MODEL_REPO, repo_type="model", filename="model.pkl")
    return joblib.load(pkl_path)

model = load_model()

st.title("Sales Forecast: Product × Store")

# Inputs
with st.form("inference"):
    col1, col2 = st.columns(2)
    with col1:
        product_id = st.text_input("Product_Id", "FD30")
        product_weight = st.number_input("Product_Weight", min_value=0.0, value=500.0)
        sugar = st.selectbox("Product_Sugar_Content", ["low sugar","regular","no sugar"])
        allocated_area = st.number_input("Product_Allocated_Area", min_value=0.0, max_value=1.0, value=0.05)
        product_type = st.text_input("Product_Type", "dairy")
    with col2:
        product_mrp = st.number_input("Product_MRP", min_value=0.0, value=199.0)
        store_id = st.text_input("Store_Id", "OUT001")
        store_est_year = st.number_input("Store_Establishment_Year", min_value=1900, max_value=2100, value=2010)
        store_size = st.selectbox("Store_Size", ["Small","Medium","High"])
        city_type = st.selectbox("Store_Location_City_Type", ["Tier 1","Tier 2","Tier 3"])
        store_type = st.selectbox("Store_Type", ["Departmental Store","Supermarket Type1","Supermarket Type2","Food Mart"])
    submitted = st.form_submit_button("Predict")

if submitted:
    # Engineered features used during training
    store_age = max(0, 2025 - int(store_est_year))
    mrp_x_area = float(product_mrp) * float(allocated_area)

    # Assemble frame in the same schema as training
    row = {
        "Product_Id": product_id,
        "Product_Sugar_Content": sugar,
        "Product_Type": product_type,
        "Store_Id": store_id,
        "Store_Size": store_size,
        "Store_Location_City_Type": city_type,
        "Store_Type": store_type,
        "Product_Weight": float(product_weight),
        "Product_Allocated_Area": float(allocated_area),
        "Product_MRP": float(product_mrp),
        "Store_Establishment_Year": int(store_est_year),
        "Store_Age": float(store_age),
        "MRP_x_Area": float(mrp_x_area),
    }
    X = pd.DataFrame([row])
    y_pred = model.predict(X)[0]
    st.metric("Predicted Product_Store_Sales_Total", f"{y_pred:,.2f}")