rahulsuren12's picture
Upload folder using huggingface_hub
64c03bc verified
import streamlit as st
import pandas as pd
import requests
# Set the title of the Streamlit app
st.title("SuperKart Total Sales Prediction App")
st.markdown("""
Welcome to the **SuperKart Sales Forecasting Tool**!
Predict total sales for a product-store combination or upload a batch of product records for multi-store forecasting.
""")
# Section for online prediction
st.subheader("Online Prediction")
# Collect user input for property features
product_weight = st.number_input("Product Weight (kg)", min_value=0.0, step=0.1)
product_area = st.number_input("Product Allocated Area (sq. m.)", min_value=0.0, step=0.1)
product_mrp = st.number_input("Product MRP (₹)", min_value=0.0, step=0.1)
store_age = st.number_input("Store Age (years)", min_value=0, step=1)
product_sugar = st.selectbox("Product Sugar Content", ["Low", "Regular", "No Sugar"])
product_type = st.selectbox("Product Type", [
"Frozen Foods", "Dairy", "Canned", "Baking Goods", "Health and Hygiene",
"Snack Foods", "Meat", "Household", "Hard Drinks", "Fruits and Vegetables",
"Breads", "Soft Drinks", "Breakfast", "Starchy Foods", "Seafood", "Others"
])
store_size = st.selectbox("Store Size", ["Small", "Medium", "Large"])
store_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_id = st.selectbox("Store ID", ["ST001", "ST002", "ST003", "ST004"])
# Convert the inputs into a dictionary for the backend
input_data = {
"Product_Weight": product_weight,
"Product_Allocated_Area": product_area,
"Product_MRP": product_mrp,
"Store_Age": store_age,
"Product_Sugar_Content": product_sugar,
"Product_Type": product_type,
"Store_Size": store_size,
"Store_Location_City_Type": store_city_type,
"Store_Type": store_type,
"Store_Id": store_id
}
# Make prediction when the "Predict" button is clicked
if st.button("Predict Sales"):
# Validate inputs before sending
if product_weight == 0 or product_area == 0 or product_mrp == 0:
st.warning("Please enter valid values for product details before predicting.")
else:
response = requests.post("https://rahulsuren12-TotalSalesPredictionBackend.hf.space/v1/sales", json=input_data) # Send data to Flask API
if response.status_code == 200:
prediction = response.json()['Predicted_Sales_Total']
st.success(f"Predicted Total Sales: ₹ {prediction:,.2f}")
else:
st.error("Error making prediction.")