saleskart / app.py
sasipriyank's picture
Upload folder using huggingface_hub
3a988cd verified
import streamlit as st
import pandas as pd
import joblib
import numpy as np
import os
# Force Streamlit to use a writable config directory
os.environ['HOME'] = '/tmp'
os.environ['STREAMLIT_HOME'] = '/tmp/.streamlit'
# Ensure the directory exists
os.makedirs(os.environ['STREAMLIT_HOME'], exist_ok=True)
# You can verify the env vars were set correctly
print("HOME =", os.environ.get("HOME"))
print("STREAMLIT_HOME =", os.environ.get("STREAMLIT_HOME"))
# Load the trained model
@st.cache_resource
def load_model():
return joblib.load("superkart_prediction_model_v1_0.joblib")
model = load_model()
# Streamlit UI for Price Prediction
st.title("superkart Prediction App")
st.write("This tool predicts the sale details.")
st.subheader("Enter the listing details:")
# Collect user input
Product_Type = st.selectbox("Product Type", ["Product_Type", "Snack Foods", "Meat","Dairy","Household","Baking Goods","Fruits and Vegetables","Canned"])
Product_Weight = st.number_input("Product Weight", min_value=10, value=10)
Product_MRP = st.number_input("Product MRP", min_value=1, value=2)
Product_Sugar_Content = st.selectbox("Product Sugar Content", ["Product_Sugar_Content", "Low Sugar", "No Sugar","Regular"])
Store_Location_City_Type = st.selectbox("Store Location City Type", ["Store_Location_City_Type", "Tier 1", "Tier 2","Tier 3"])
Product_Allocated_Area= st.number_input("Product Allocated Area",min_value=0.0, max_value=100.0, step=1.0, value=90.0)
Store_Type= st.selectbox("Store Type", ["Store_Type", "Food Mart", "Supermarket Type1","Departmental Store"])
Store_Size= st.selectbox("Store Size", ["Store_Size", "1", "2","3"])
Store_Id= st.selectbox("Store Id", ["Store_Id", "OUT001", "OUT002","OUT003","OUT004"])
from datetime import datetime
# Get current year
current_year = datetime.now().year
# Generate a list of years from 1987 to current year
years = ["Store_Establishment_Year"] + [str(year) for year in range(1987, current_year + 1)]
# Create selectbox
Store_Establishment_Year = st.selectbox("Store Establishment Year", years)
# Convert user input into a DataFrame
input_data = pd.DataFrame([{
'Product_Type': Product_Type,
'Product_Weight': Product_Weight,
'Product_MRP': Product_MRP,
'Product_Sugar_Content': Product_Sugar_Content,
'Store_Location_City_Type': Store_Location_City_Type,
'Product_Allocated_Area': Product_Allocated_Area,
'Store_Type': Store_Type,
'Store_Size': Store_Size,
'Store_Id': Store_Id,
'Store_Establishment_Year': Store_Establishment_Year
}])
# Predict button
if st.button("Predict"):
prediction = model.predict(input_data)
st.write(f"The predicted price of the sale is ${np.exp(prediction)[0]:.2f}.")