import streamlit as st import requests # ✅ Hugging Face backend API endpoint (Flask) API_URL = "https://Akshat747-SuperKart.hf.space/predict" # change this after deploying Flask backend st.set_page_config(page_title="SuperKart Sales Predictor", layout="wide") st.title("🛒 SuperKart Sales Predictor") st.write("Enter product & store details below to predict sales:") # Input fields product_weight = st.number_input("Product Weight", min_value=0.0, format="%.2f") allocated_area = st.number_input("Product Allocated Area", min_value=0) mrp = st.number_input("Product MRP", min_value=0.0, format="%.2f") sugar_content = st.selectbox("Product Sugar Content", ["Low", "Regular", "No Sugar"]) product_type = st.text_input("Product Type", "Snack Foods") store_size = st.selectbox("Store Size", ["small", "medium", "high"]) est_year = st.number_input("Store Establishment Year", min_value=1900, max_value=2025, value=2012) location_type = st.selectbox("Store Location City Type", ["Tier 1", "Tier 2", "Tier 3"]) store_type = st.selectbox("Store Type", ["Supermarket", "Grocery", "Convenience"]) if st.button("Predict Sales"): payload = { "Product_Weight": product_weight, "Product_Allocated_Area": allocated_area, "Product_MRP": mrp, "Product_Sugar_Content": sugar_content, "Product_Type": product_type, "Store_Size": store_size, "Store_Establishment_Year": est_year, "Store_Location_City_Type": location_type, "Store_Type": store_type } try: response = requests.post(API_URL, json=payload) if response.status_code == 200: result = response.json() if "prediction" in result: st.success(f"✅ Predicted Sales: **{result['prediction']:.2f} units**") else: st.error(f"⚠️ Error: {result}") else: st.error(f"⚠️ Backend Error {response.status_code}") except Exception as e: st.error(f"⚠️ Connection failed: {e}")