AIForecaster's picture
Upload folder using huggingface_hub
e5ff856 verified
import streamlit as st
import pandas as pd
import requests
# Set the title of the Streamlit app
st.title("SuperKart Retail Store Sales Predictor App")
# Section for online prediction
st.subheader("This tool predicts SuperKart Retail Store Sales based on the product and store details. Enter the required information below.")
st.subheader("Enter the Product and Store details:")
# Collect user input
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"])
Store_Type = st.selectbox("Store Type",["Supermarket Type2","Supermarket Type1","Departmental Store","Food Mart"])
Product_Weight = st.number_input("Product Weight (Lbs):",min_value = 0.01, value = 12.60, max_value = 30.00)
Product_MRP = st.number_input("Product MRP ($):",min_value = 1.00, value = 150.00, max_value = 300.00)
Product_Allocated_Area = st.number_input("Product Allocated Area (%):",min_value = 0.001, value = 0.060, max_value = 0.350)
# Convert user input into a DataFrame
input_data = pd.DataFrame([{
"Product_Weight" : Product_Weight,
"Product_Allocated_Area" : Product_Allocated_Area,
"Product_MRP" : Product_MRP,
"Product_Sugar_Content" : Product_Sugar_Content,
"Product_Type" : Product_Type,
"Store_Type" : Store_Type
}])
# Make prediction when the "Predict" button is clicked
if st.button("Predict"):
# Convert the DataFrame to a dictionary that is JSON serializable
# Since input_data is a single row DataFrame, .to_dict(orient='records')[0] will give us the first (and only) row as a dictionary.
response = requests.post("https://AIForecaster-Superkart-Store-Revenue-PredictionBackend.hf.space/v1/superkart", json=input_data.to_dict(orient='records')[0]) # Send data to Flask API
if response.status_code == 200:
prediction = response.json()['Predicted Store Sales (in Dollars)']
st.success(f"Predicted Store Sales (in dollars): {prediction}")
else:
st.error("Error making prediction.")