Dewasheesh's picture
Upload folder using huggingface_hub
e74eeac verified
import streamlit as st
import pandas as pd
import joblib
import requests
model_root_url = "https://Dewasheesh-SuperKartPredictionBackend.hf.space" # Base URL of the deployed Flask API on Hugging Face Space; enter user name and space name before running the cell
model_url = model_root_url + "/v1/superkart"
# Streamlit UI for Super Kart Sales Prediction
st.title("Super Kart Sales Prediction App")
st.write("This tool predicts the total store sales based on product and store details. Enter the required information below:")
# Collect user input based on dataset columns
Product_Weight = st.number_input("Product Weight", min_value=0.0, value=10.0)
Product_Sugar_Content = st.selectbox("Product Sugar Content", ["Low", "Medium", "High"])
Product_Allocated_Area = st.number_input("Product Allocated Area (sq. ft.)", min_value=0.0, value=50.0)
Product_Type = st.selectbox("Product Type", ["Food", "Drinks", "Household", "Others"])
Product_MRP = st.number_input("Product MRP (Maximum Retail Price)", min_value=0.0, value=100.0)
Store_Id = st.text_input("Store ID (e.g., S001)", "S001")
Store_Establishment_Year = st.number_input("Store Establishment Year", min_value=1900, max_value=2025, value=2010)
Store_Size = st.selectbox("Store Size", ["Small", "Medium", "High"])
Store_Location_City_Type = st.selectbox("Store Location City Type", ["Tier 1", "Tier 2", "Tier 3"])
Store_Type = st.selectbox("Store Type", ["Grocery Store", "Supermarket", "Hypermarket", "Others"])
# Convert categorical + numerical inputs into DataFrame
input_data = pd.DataFrame([{
'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_Id': Store_Id,
'Store_Establishment_Year': Store_Establishment_Year,
'Store_Size': Store_Size,
'Store_Location_City_Type': Store_Location_City_Type,
'Store_Type': Store_Type
}])
# Predict button
if st.button("Predict Sales"):
# Convert dataframe row to dict for JSON serialization
payload = input_data.to_dict(orient="records")[0]
try:
response = requests.post(model_url, json=payload)
if response.status_code == 200:
result = response.json()
# Assuming backend returns {"Predicted Sales Total": value}
predicted_sales = result.get("Predicted Sales Total", None)
if predicted_sales is not None:
st.write(f"### Predicted Sales Total: **{round(float(predicted_sales), 2)}**")
else:
st.error("Response JSON missing 'Predicted Sales Total'")
else:
st.error(f"Error: {response.status_code} - {response.text}")
except Exception as e:
st.error(f"Request failed: {e}")