import streamlit as st import requests import pandas as pd st.set_page_config(page_title="SuperKart Sales Forecast", page_icon="🛒") st.title("SuperKart Sales Forecast") st.write("Enter product and store details to get the predicted sales for the upcoming quarter.") # Replace with your actual backend Space URL after it is created BACKEND_URL = "https://premswan-superkart-be.hf.space/predict" with st.form("input_form"): product_id = st.text_input("Product Id", value="FD01") product_weight = st.number_input("Product Weight", min_value=0.0, step=0.1) product_sugar_content = st.selectbox("Product Sugar Content", ["low", "regular", "no sugar"]) product_allocated_area = st.number_input("Allocated Area (display area for product)", min_value=0.0, step=1.0) product_type = st.text_input("Product Type", value="snack") product_mrp = st.number_input("Product MRP", min_value=0.0, step=1.0) store_id = st.text_input("Store Id", value="S001") store_est_year = st.number_input("Store Establishment Year", min_value=1950, max_value=2024, value=2010) store_size = st.selectbox("Store Size", ["Small", "Medium", "High"]) store_city_type = st.selectbox("Store Location City Type", ["Tier 1", "Tier 2", "Tier 3"]) store_type = st.text_input("Store Type", value="Supermarket Type1") submitted = st.form_submit_button("Predict Sales") if submitted: current_year = 2024 store_age = current_year - store_est_year payload = { "Product_Id": product_id, "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_Id": store_id, "Store_Establishment_Year": int(store_est_year), "Store_Size": store_size, "Store_Location_City_Type": store_city_type, "Store_Type": store_type, "Store_Age": store_age, } try: response = requests.post(BACKEND_URL, json=payload, timeout=30) if response.status_code == 200: result = response.json() predicted_sales = result.get("predicted_sales", None) st.success(f"Predicted Quarterly Sales: {predicted_sales:,.2f}") else: st.error(f"Backend error (status {response.status_code}): {response.text}") except Exception as e: st.error(f"Error connecting to backend: {e}")