critical12's picture
Upload folder using huggingface_hub
6ef6b69 verified
import streamlit as st
import pandas as pd
import requests
# Streamlit UI for Product Store Sales Prediction
st.title("Product Store Sales Prediction App")
st.write("This tool predicts the total sales of a product in a store based on its attributes. Enter the required information below.")
# Collect user input based on dataset columns
access_token = st.text_input("Hf access token")
Product_Id = st.text_input("Product ID (e.g., AB12345)")
Product_Weight = st.number_input("Product Weight (kg)", min_value=0.0, value=100.0)
Product_Sugar_Content = st.selectbox("Product Sugar Content", ["Low Sugar", "Regular", "No Sugar"])
Product_Allocated_Area = st.number_input("Product Allocated Area (ratio)", min_value=0.0, max_value=1.0, value=0.1)
Product_Type = st.selectbox("Product Type", [
"Meat", "Snack Foods", "Hard Drinks", "Dairy", "Canned", "Soft Drinks",
"Health and Hygiene", "Baking Goods", "Bread", "Breakfast", "Frozen Foods",
"Fruits and Vegetables", "Household", "Seafood", "Starchy Foods", "Others"
])
Product_MRP = st.number_input("Product MRP (₹)", min_value=0.0, value=1000.0)
Store_Id = st.text_input("Store ID (e.g., S123)")
Store_Establishment_Year = st.number_input("Store Establishment Year", min_value=1900, max_value=2025, value=2000)
Store_Size = st.selectbox("Store Size", ["High", "Medium", "Low"])
Store_Location_City_Type = st.selectbox("Store Location City Type", ["Tier 1", "Tier 2", "Tier 3"])
Store_Type = st.selectbox("Store Type", ["Departmental Store", "Supermarket Type 1", "Supermarket Type 2", "Food Mart"])
# Convert inputs to match model training
product_store_data = {
'Product_Id': Product_Id,
'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
}
if st.button("Predict", type='primary'):
headers = {
"Authorization": f"Bearer {access_token}"
}
response = requests.post("https://critical12-superkart-backend.hf.space/v1/productstore", json=product_store_data, headers=headers)
if response.status_code == 200:
result = response.json()
predicted_sales = result["Predicted_Sales"] # Extract only the value
st.write(f"Based on the information provided, the predicted total sales for Product ID {Product_Id} in Store ID {Store_Id} is ₹{predicted_sales}.")
else:
st.error("Error in API request")