zezkcy's picture
Upload folder using huggingface_hub
1b9a2b2 verified
import streamlit as st
import pandas as pd
import requests
# Title
st.title("SuperKart Sales Price Predictor")
# ------------- Online Prediction ----------------
st.subheader("Online Prediction")
# Required store outlet columns after encoding
required_store_columns = ['Store_OUT001', 'Store_OUT002', 'Store_OUT003', 'Store_OUT004']
product_weight = st.number_input("Product Weight (kg)", min_value=0.0)
product_allocated_area = st.number_input("Product Allocated Area", min_value=0.0)
product_mrp = st.number_input("Product MRP", min_value=0.0)
store_year = st.number_input("Store Establishment Year", min_value=1990, max_value=2025)
product_sugar_content = st.selectbox("Sugar Content", ["Low Sugar", "Regular", "No Sugar"])
store_size = st.selectbox("Store Size", ["High", "Medium", "Low"])
store_location = st.selectbox("City Tier", ["Tier 1", "Tier 2", "Tier 3"])
store_type = st.selectbox("Store Type", ["Supermarket Type1", "Supermarket Type2", "Departmental Store", "Food Mart"])
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_id = st.selectbox("Store ID", ["Store_OUT001", "Store_OUT002", "Store_OUT003", "Store_OUT004"])
input_data = pd.DataFrame([{
"Product_Weight": product_weight,
"Product_Allocated_Area": product_allocated_area,
"Product_MRP": product_mrp,
"Store_Establishment_Year": store_year,
"Product_Sugar_Content": product_sugar_content,
"Store_Size": store_size,
"Store_Location_City_Type": store_location,
"Store_Type": store_type,
"Product_Type": product_type,
"Store_ID": store_id
}])
# One-hot encode store id
for col in required_store_columns:
input_data[col] = 1 if col == f'Store_{store_id}' else 0
# Convert to DataFrame
input_df = input_data
if st.button("Predict"):
try:
response = requests.post(
"https://zezkcy-SalePricePredictionBackendDemo.hf.space/v1/sales", # πŸ” UPDATE THIS
json=input_df.to_dict(orient='records')[0]
)
if response.status_code == 200:
prediction = response.json().get("Predicted Sales", "No prediction returned")
st.success(f"Predicted Sales: ${prediction}")
else:
st.error("Error in prediction.")
st.text(response.text)
except Exception as e:
st.error(f"Exception: {e}")
# ------------- Batch Prediction ----------------
st.subheader("Batch Prediction")
uploaded_file = st.file_uploader("Upload CSV file", type=["csv"])
if uploaded_file is not None:
if st.button("Predict Batch"):
try:
files = {"file": (uploaded_file.name, uploaded_file, "text/csv")}
response = requests.post(
"https://zezkcy-SalePricePredictionBackendDemo.hf.space/v1/salesbatch", # πŸ” UPDATE THIS
files=files
)
if response.status_code == 200:
predictions = response.json()
st.success("Batch prediction complete.")
st.dataframe(pd.DataFrame(predictions))
else:
st.error("Batch prediction failed.")
st.text(response.text)
except Exception as e:
st.error(f"Exception: {e}")