chaitram's picture
Upload folder using huggingface_hub
1aafc76 verified
Raw
History Blame Contribute Delete
2.81 kB
import streamlit as st
import pandas as pd
import requests
# Set the title of the Streamlit app
st.title("Product Store Sales Prediction")
st.write("Enter product and store details to predict total sales.")
# Section for online prediction
st.subheader("Product Details")
# Collect user input for property features
Product_Weight = st.number_input(
"Product Weight",
min_value=0.0,
step=0.1,
value=10.0
)
Product_Sugar_Content = st.selectbox(
"Product Sugar Content",
["Low Sugar", "Regular", "No Sugar"]
)
Product_Allocated_Area = st.number_input(
"Product Allocated Area (Ratio)",
min_value=0.0,
max_value=1.0,
step=0.01,
value=0.10
)
Product_Type = st.selectbox(
"Product Type",
[
"Meat", "Snack Foods", "Hard Drinks", "Dairy", "Canned",
"Soft Drinks", "Health and Hygiene", "Baking Goods", "Bread",
"Breakfast", "Frozen Foods", "Fruits and Vegetables",
"Household", "Seafood", "Starchy Foods", "Others"
]
)
Product_MRP = st.number_input(
"Product MRP",
min_value=0.0,
step=1.0,
value=100.0
)
# -----------------------------
# Store Inputs
# -----------------------------
st.subheader("๐Ÿฌ Store Details")
Store_Establishment_Year = st.number_input(
"Store Establishment Year",
min_value=1950,
max_value=2025,
step=1,
value=2005
)
Store_Size = st.selectbox(
"Store Size",
["Low", "Medium", "High"]
)
Store_Location_City_Type = st.selectbox(
"Store Location City Type",
["Tier 1", "Tier 2", "Tier 3"]
)
Store_Type = st.selectbox(
"Store Type",
[
"Departmental Store",
"Supermarket Type 1",
"Supermarket Type 2",
"Food Mart"
]
)
# -----------------------------
# Prediction
# -----------------------------
if st.button("๐Ÿ”ฎ Predict Sales"):
payload = {
"Product_Weight": Product_Weight,
"Product_Sugar_Content": Product_Sugar_Content,
"Product_Allocated_Area": Product_Allocated_Area,
"Product_Type": Product_Type,
"Product_MRP": Product_MRP,
"Store_Establishment_Year": Store_Establishment_Year,
"Store_Size": Store_Size,
"Store_Location_City_Type": Store_Location_City_Type,
"Store_Type": Store_Type
}
try:
response = requests.post(
"https://chaitram-salespredictionbackend.hf.space/v1/sales",
json=payload,
timeout=10
)
if response.status_code == 200:
prediction = response.json()["predicted_sales"]
st.success(f"๐Ÿ’ฐ Predicted Product Store Sales: **{prediction:,.2f}**")
else:
st.error("โŒ Prediction failed. Please check API logs.")
except Exception as e:
st.error(f"โš ๏ธ API connection error: {e}")