SuperKartFE / app.py
asvravi's picture
Upload folder using huggingface_hub
2fdb36b verified
import requests
import streamlit as st
import pandas as pd
st.title ("SuperKart Sales Forecast")
st.write ("Sales forecast for your product")
# Product Details
st.subheader ("Product Details")
prod_weight = st.number_input ("Weight", min_value=0.0, max_value=200.0, value=10.0, step=0.1)
prod_alloc_area = st.number_input ("Allocated Area (fraction 0-1)", min_value=0.0, max_value=1.0, value=0.1)
prod_mrp = st.number_input ("MRP", min_value=0.0, max_value=1000.0, value=200.0, step=1.0)
prod_sug_content = st.selectbox ("Sugar Content", ['Low Sugar', 'Regular', 'No Sugar'])
prod_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', 'Others', 'Starchy Foods', 'Seafood'
])
# Store Details
st.subheader ("Store Details")
# Dictionary mapping store IDs to establishment years
store_data = {
'OUT001': 1987,
'OUT002': 1998,
'OUT003': 1999,
'OUT004': 2009
}
# Store IDs and their corresponding establishment years
store_ids = ['OUT001', 'OUT002', 'OUT003', 'OUT004']
establishment_years = [1987, 1998, 1999, 2009]
# Create a mapping of store_id to year
store_map = dict(zip(store_ids, establishment_years))
# Dropdown for selecting Store ID
store_id = st.selectbox("Select Store ID", store_ids)
# Auto-select the corresponding establishment year (as single-option dropdown)
matched_year = store_map[store_id]
store_estb_year = st.selectbox("Establishment Year (auto-selected)", options=[matched_year], index=0, disabled=True)
store_size = st.selectbox ("Store Size", ['Small', 'Medium', 'High'])
store_city_type = st.selectbox ("Type of City", ['Tier 1', 'Tier 2', 'Tier 3'])
store_type = st.selectbox ("Store Type", ['Food Mart', 'Departmental Store', 'Supermarket Type1', 'Supermarket Type2'])
# Single sales forecast
if st.button("Forecast Sales for Single Product", type='primary'):
# extract the data collected into a structure
input_data = {
'Product_Weight' : prod_weight,
'Product_Sugar_Content' : prod_sug_content,
'Product_Allocated_Area' : prod_alloc_area,
'Product_Type' : prod_type,
'Product_MRP' : prod_mrp,
'Store_Id' : store_id,
'Store_Establishment_Year' : store_estb_year,
'Store_Size' : store_size,
'Store_Location_City_Type' : store_city_type,
'Store_Type' : store_type
}
response = requests.post (
"https://asvravi-SuperKartBE.hf.space/v1/SuperKartSales",
json=input_data
)
if response.status_code == 200:
result = response.json ()
sales_forecast = result.get ("SalesForecast") # Extract only the value
st.success (f"The sales forecast for given input is {sales_forecast:.2f}.")
else:
st.error (f"Error in API request - {response.status_code}")
# ==============================
# Batch Prediction
# ==============================
st.subheader ("Batch Forecast of SuperKart Sales")
file = st.file_uploader ("Upload CSV file", type=["csv"])
if file is not None:
if st.button("Forecast Sales for Batch", type='primary'):
inputfile = {"file": (file.name, file.getvalue(), "text/csv")}
response = requests.post(
"https://asvravi-SuperKartBE.hf.space/v1/SuperKartBatchSales",
files=inputfile
)
if response.status_code == 200:
st.header("Batch Forecast Results")
result = response.json ()
# convert dict to dataframe for better display
result_df = pd.DataFrame(list(result.items()), columns=["Product_Id", "Predicted_Sales"])
result_df["Predicted_Sales"] = result_df["Predicted_Sales"].astype(float).round(2)
st.dataframe (result_df)
#st.write(result)
else:
st.error (f"Error in API request {response.status_code}")