omoral02's picture
Upload folder using huggingface_hub
36cda40 verified
import streamlit as st
import pandas as pd
import joblib
import numpy as np
import requests
# UI Title and Subtitle
st.title("๐Ÿ›’ SuperKart Sales Forecasting App")
st.write("This tool predicts **product-level revenue** in a specific store using historical and categorical inputs.")
# UI for Input Features
st.subheader("Enter Product & Store Details:")
# Categorical Inputs
product_type = st.selectbox("Product Type", [
"Meat", "Snack Foods", "Soft Drinks", "Dairy", "Household", "Fruits and Vegetables",
"Frozen Foods", "Breakfast", "Baking Goods", "Health and Hygiene", "Starchy Foods"
])
store_type = st.selectbox("Store Type", [
"Supermarket Type1", "Supermarket Type2", "Supermarket Type3", "Grocery Store"
])
city_type = st.selectbox("City Type", ["Tier 1", "Tier 2", "Tier 3"])
store_size = st.selectbox("Store Size", ["Small", "Medium", "High"])
sugar_content = st.selectbox("Product Sugar Content", ["No Sugar", "Low Sugar", "Regular"])
# Numerical Inputs
product_weight = st.number_input("Product Weight (kg)", min_value=0.0, max_value=50.0, value=10.0, step=0.1)
product_mrp = st.number_input("Product MRP", min_value=0.0, max_value=1000.0, value=200.0, step=1.0)
allocated_area = st.number_input("Allocated Display Area (0-1)", min_value=0.0, max_value=1.0, value=0.2, step=0.01)
store_est_year = st.number_input("Store Establishment Year", min_value=1950, max_value=2025, value=2010)
# Convert to DataFrame
input_data = pd.DataFrame({
'Product_Type': [product_type],
'Store_Type': [store_type],
'Store_Location_City_Type': [city_type],
'Store_Size': [store_size],
'Product_Sugar_Content': [sugar_content],
'Product_Weight': [product_weight],
'Product_MRP': [product_mrp],
'Product_Allocated_Area': [allocated_area],
'Store_Establishment_Year': [store_est_year],
})
# Make prediction when the "Predict" button is clicked
if st.button("Predict"):
response = requests.post("https://omoral02-RevenuePredictionBackend.hf.space/v1/predict", json=input_data.to_dict(orient='records')[0]) # Send data to Flask API
if response.status_code == 200:
prediction = response.json()['Predicted_Store_Sales_Total']
st.success(f"Predicted Revenue (in dollars): {prediction}")
else:
st.error("Error making prediction.")
# Section for batch prediction
st.subheader("Batch Prediction")
# Allow users to upload a CSV file for batch prediction
uploaded_file = st.file_uploader("Upload CSV file for batch prediction", type=["csv"])
# Make batch prediction when the "Predict Batch" button is clicked
if uploaded_file is not None:
if st.button("Predict Batch"):
response = requests.post("https://omoral02-RevenuePredictionBackend.hf.space/v1/batch", files={"file": uploaded_file}) # Send file to Flask API
if response.status_code == 200:
predictions = response.json()
st.success("Batch predictions completed!")
st.write(predictions) # Display the predictions
else:
st.error("Error making batch prediction.")