app-frontend / app.py
rahulg1987's picture
Update app.py
4429e8e verified
import streamlit as st
import pandas as pd
import requests
# Streamlit UI for Sales price Prediction
st.title("SuperKart Sales Prediction App")
st.write("This tool predicts sales price based on product details. Enter the required information below.")
# Collect user input based on dataset columns
ProductWeight = st.number_input("Product Weight", min_value=0.1, max_value=500.0)
ProductSugarContent = st.selectbox("Product Sugar Content", ["Low Sugar", "Regular", "No Sugar"])
ProductAllocatedArea = st.number_input("Product Allocated Area", min_value=0.01, max_value=500.0)
ProductType = 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"])
ProductMRP = st.number_input("Product MRP", min_value=0.1, max_value=5000000.0)
StoreId = st.selectbox("Store Id", ["OUT001", "OUT002", "OUT003","OUT004"])
StoreEstablishmentYear = st.selectbox("Store Establishment Year", ["1987", "1998", "1999","2009"])
StoreSize = st.selectbox("Store Size", ["Small", "Medium", "High"])
StoreLocationCityType = st.selectbox("Store Location City Type", ["Tier 1", "Tier 2", "Tier 3"])
StoreType = st.selectbox("Store Type", ["Supermarket Type1", "Supermarket Type2", "Departmental Store", "Food Mart"])
# Convert categorical inputs to match model training
product_data = {'Product_Weight': ProductWeight,'Product_Sugar_Content': ProductSugarContent,'Product_Allocated_Area': ProductAllocatedArea,'Product_Type': ProductType,'Product_MRP':ProductMRP,'Store_Id': StoreId,'Store_Establishment_Year': StoreEstablishmentYear,'Store_Size': StoreSize,'Store_Location_City_Type': StoreLocationCityType,'Store_Type': StoreType}
if st.button("Predict", type='primary'):
response = requests.post("https://rahulg1987-app-backend.hf.space/v1/totalsales", json=product_data)
if response.status_code == 200:
result = response.json()
prediction = result["predicted_sales"] # Extract only the value
st.write(f"Based on the product information provided, The sales price will be {prediction}.")
else:
st.error(response.status_code)