debasishdas1985's picture
Upload folder using huggingface_hub
d55e436 verified
import streamlit as st
import pandas as pd
import requests
# Set the title of the Streamlit app
st.title("Store Product Sales Prediction")
# Section for online prediction
st.subheader("Online Prediction")
# Collect user input for property features
# Using selectbox for categorical features to match model expectations
Product_Sugar_Content = st.selectbox("Sugar Content", ["Low Sugar", "Regular", "No Sugar"])
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"])
Store_Size = st.selectbox("Store Size", ["High", "Medium", "Small"])
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 Type1", "Supermarket Type2", "Food Mart"])
# Numerical inputs
Product_Weight = st.number_input("Product Weight", min_value=0.0, value=10.0)
Product_Allocated_Area = st.number_input("Product Allocated Area", min_value=0.0, value=0.05)
Product_MRP = st.number_input("Product MRP", min_value=0.0, value=100.0)
Store_Age = st.number_input("Store Age", min_value=0, value=10)
# Convert user input into a DataFrame
input_data = pd.DataFrame([{
'Product_Sugar_Content': Product_Sugar_Content,
'Product_Type': Product_Type,
'Store_Size': Store_Size,
'Store_Location_City_Type': Store_Location_City_Type,
'Store_Type': Store_Type,
'Product_Weight': Product_Weight,
'Product_Allocated_Area': Product_Allocated_Area,
'Product_MRP': Product_MRP,
'Store_Age': Store_Age
}])
# Make prediction when the "Predict" button is clicked
if st.button("Predict"):
# Replace with your actual Backend URL if different
backend_url = "https://debasishdas1985-StoreSalesPredictionBackend.hf.space/v1/predict"
try:
response = requests.post(backend_url, json=input_data.to_dict(orient='records')[0])
if response.status_code == 200:
prediction = response.json().get('Predicted Sales (in dollars)')
st.success(f"Predicted Store Sales (in dollars): {prediction}")
else:
st.error(f"Error: {response.status_code} - {response.text}")
except Exception as e:
st.error(f"Connection Error: {e}")