import requests import streamlit as st st.title("SuperKart Sales Predictor") # Input fields for product and store data (same as LC) Product_Weight = st.number_input("Product Weight", min_value=0.0, value=12.66) Product_Sugar_Content = st.selectbox("Product Sugar Content", ["Low Sugar", "Regular", "No Sugar"]) Product_Allocated_Area = st.number_input("Product Allocated Area", min_value=0.0, value=0.05) Product_MRP = st.number_input("Product MRP", min_value=0.0, value=200.0) Store_Size = st.selectbox("Store Size", ["High", "Medium", "Low"]) Store_Location_City_Type = st.selectbox("Store Location City Type", ["Tier 1", "Tier 2", "Tier 3"]) Store_Type = st.selectbox("Store Type", ["Departmental Store", "Supermarket Type 1", "Supermarket Type 2", "Food Mart"]) Product_Id_char = st.text_input("Product ID (first 2 letters)", "FD") Store_Age_Years = st.number_input("Store Age (years)", min_value=0, value=10) Product_Type_Category = st.selectbox( "Product Type Category", [ "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" ] ) # --- Minimal additions to satisfy backend --- # Store_Id expected by pipeline Store_Id = st.number_input("Store Id", min_value=1, value=1, step=1) # Product_Type_Clean expected by pipeline. If your training cleaned/normalized names, # the simplest safe fallback is to pass the selected category through unchanged: Product_Type_Clean = Product_Type_Category # keep identical unless your backend requires specific cleaning # Payload (same keys as LC + 2 required by backend) product_data = { "Product_Weight": Product_Weight, "Product_Sugar_Content": Product_Sugar_Content, "Product_Allocated_Area": Product_Allocated_Area, "Product_MRP": Product_MRP, "Store_Size": Store_Size, "Store_Location_City_Type": Store_Location_City_Type, "Store_Type": Store_Type, "Product_Id_char": Product_Id_char, "Store_Age_Years": Store_Age_Years, "Product_Type_Category": Product_Type_Category, "Store_Id": int(Store_Id), "Product_Type_Clean": Product_Type_Clean, } # Call backend (same flow as LC; minimal safety added) if st.button("Predict", type="primary"): try: response = requests.post( "https://johnny-five-c-SuperKartBackend.hf.space/v1/predict", json=product_data, timeout=15 ) if response.status_code == 200: result = response.json() predicted_sales = result.get("result", result.get("prediction")) if isinstance(predicted_sales, list): predicted_sales = predicted_sales[0] if predicted_sales is None: st.error("Unexpected response format.") else: st.success(f"Predicted Product_Store Sales Total: {float(predicted_sales):.2f}") else: st.error(f"Error in API request: {response.status_code} - {response.text}") except Exception as e: st.error(f"Request failed: {e}")