Dtapkir's picture
Upload folder using huggingface_hub
09cbf01 verified
from datetime import datetime
import streamlit as st
import pandas as pd
import requests
# -------------------------
# SuperKart Streamlit UI
# -------------------------
st.title("SuperKart Sales Revenue Predictor")
st.markdown("""
Use this app to predict the **expected sales revenue** for a given product
based on its characteristics and store details.
""")
# -------------------------
# Online Prediction Section
# -------------------------
st.subheader("Single Product Prediction")
# --- Collect user inputs ---
Product_Weight = st.number_input("Product Weight (in kg)", min_value=0.0, step=0.1)
Product_Allocated_Area = st.number_input("Product Allocated Area", min_value=0.0, step=0.1)
Product_MRP = st.number_input("Product MRP (Maximum Retail Price)", min_value=0.0, step=0.5)
Product_Sugar_Content = st.selectbox(
"Product Sugar Content",
["Low Sugar", "Regular", "No Sugar", "reg"]
)
Product_Type = st.selectbox(
"Product Type",
[
"Fruits and Vegetables", "Snack Foods", "Frozen Foods", "Dairy", "Household",
"Baking Goods", "Canned", "Health and Hygiene", "Meat", "Soft Drinks",
"Breads", "Hard Drinks", "Others", "Starchy Foods", "Breakfast", "Seafood"
]
)
Store_Size = st.selectbox("Store Size", ["Medium", "High", "Small"])
Store_Location_City_Type = st.selectbox(
"Store Location City Type",
["Tier 1", "Tier 2", "Tier 3"]
)
Store_Type = st.selectbox(
"Store Type",
["Supermarket Type1", "Supermarket Type2", "Departmental Store", "Food Mart"]
)
Store_Establishment_Year = st.number_input(
"Store Establishment Year", min_value=1980, max_value=datetime.now().year, value=2010
)
# --- Prepare input data ---
input_data = pd.DataFrame([{
"Product_Weight": Product_Weight,
"Product_Allocated_Area": Product_Allocated_Area,
"Product_MRP": Product_MRP,
"Product_Sugar_Content": Product_Sugar_Content,
"Product_Type": Product_Type,
"Store_Establishment_Year": Store_Establishment_Year,
"Store_Size": Store_Size,
"Store_Location_City_Type": Store_Location_City_Type,
"Store_Type": Store_Type
}])
if st.button("Predict Sales Revenue"):
with st.spinner("Predicting..."):
response = requests.post("https://Dtapkir-SuperkartSalesPredictionBackend.hf.space/v1/predict",
json=input_data.to_dict(orient="records")[0])
# --- Check for success ---
if response.status_code == 200:
result = response.json()
# Debug: display entire response
st.write("API Response:", result)
# Extract prediction safely
prediction = result.get("Predicted_Product_Store_Sales_Total", None)
if prediction is not None:
st.success(f"Predicted Sales Revenue (in dollars): **${prediction}**")
else:
st.warning("Prediction key not found in API response.")
else:
st.error(f"Error making prediction. Status code: {response.status_code}")
st.write("Response text:", response.text)