superkart / app.py
krishpvg's picture
Upload folder using huggingface_hub
e8857e4 verified
import streamlit as st
import pandas as pd
import numpy as np
import requests
# Streamlit UI for Superkart Sales Prediction
st.title("Superkart Sales Predictor API")
st.write("This tool predicts next quarter sales for superkart. Enter the required information below.")
# Collect user input based on dataset columns
Store_Id = st.selectbox("Store_Id", ["OUT001","OUT002","OUT003","OUT004"])
Store_Size = st.selectbox("Store_Size", ["Medium", "High", "Small"])
Store_Type = st.selectbox("Store_Type", ["Supermarket Type2", "Supermarket Type1","Departmental Store", "Food Mart"])
Store_Location_City_Type = st.selectbox("Store_Location_City_Type", ["Tier 1", "Tier 2", "Tier 3"])
Store_Establishment_Year = st.number_input("Store_Establishment_Year", min_value=1987, max_value=2009, step=1)
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"])
Product_Sugar_Content = st.selectbox("Product_Sugar_Content", ["Low Sugar", "Regular", "No Sugar", "reg"])
Product_Weight = st.number_input("Product_Weight", min_value=4.0, max_value=22.0, step=1.0)
Product_Allocated_Area = st.number_input("Product_Allocated_Area", min_value=0.004, max_value=0.298, step=0.004)
Product_MRP = st.number_input("Product_MRP", min_value=31.0, value=226.0, step=1.0)
# Convert categorical inputs to match model training
product_data = {
'Product_Type': Product_Type,
'Product_Sugar_Content': Product_Sugar_Content,
'Product_Weight': Product_Weight,
'Product_Allocated_Area': Product_Allocated_Area,
'Product_MRP': Product_MRP,
'Store_Id': Store_Id,
'Store_Size': Store_Size,
'Store_Type': Store_Type,
'Store_Location_City_Type': Store_Location_City_Type,
'Store_Establishment_Year': Store_Establishment_Year
}
if st.button("Predict", type='primary'):
response = requests.post("https://krishpvg-sample2.hf.space/v1/sales", json=product_data) # enter user name and space name before running the cell
if response.status_code == 200:
result = response.json()
sales_prediction = result["prediction"] # Extract only the value
actual_sales_prediction = np.exp(sales_prediction)
st.write(f"The predicted sales is ${actual_sales_prediction:.2f}.")
else:
st.error("Error in API request")