Backend / app.py
MattVarg's picture
Update
5ec898a verified
import streamlit as st
import pandas as pd
import joblib
import numpy as np
# Load the trained model
@st.cache_resource
def load_model():
return joblib.load("super_kart_prediction_model_v1_0.joblib")
model = load_model()
# Streamlit UI for Price Prediction
st.title("Super Kart Forecasting App")
st.write("This tool predicts the Sales Strategies")
st.subheader("Enter the listing details:")
# Collect user input
product_weight = st.number_input("Weight", min_value=1, step=1, value=2)
Product_Sugar_Content = st.selectbox("Sugar", ["Low", "Regular", "No"])
Product_Allocated_Area = st.number_input("Area", min_value=1, step=1, value=2)
Product_Type = st.selectbox("Product type", ["meat", "snack foods", "hard drinks", "dairy", "canned", "soft drinks", "health","hygiene", "baking goods", "bread", "breakfast", "frozen foods", "fruits","vegetables", "household", "seafood", "starchy foods", "others"])
Product_MRP = st.number_input("MRP", min_value=1, step=1, value=2)
Store_Establishment_Year = st.number_input("year", min_value=1950, step=1, value=2)
Store_Size = st.selectbox("Store Size", ["High", "Medium", "Low"])
Store_Location_City_Type = st.selectbox("Store 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 user input into a DataFrame
input_data = pd.DataFrame([{
'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_Establishment_Year': Store_Establishment_Year,
'Store_Size': Store_Size,
'Store_Location_City_Type': Store_Location_City_Type,
'Store_Type': Store_Type
}])
# Predict button
if st.button("Predict"):
prediction = model.predict(input_data)
st.write(f"The predicted value ${np.exp(prediction)[0]:.2f}.")