Spaces:
Runtime error
Runtime error
| import streamlit as st | |
| import requests | |
| st.set_page_config(page_title="SuperKart Sales Predictor", layout="centered") | |
| st.title("SuperKart — Sales Predictor") | |
| st.write("Enter product & store features to predict Product_Store_Sales_Total") | |
| # 🔥 Hardcoded backend URL | |
| BACKEND_URL = "https://swetha1929-superkart-backend.hf.space/predict" | |
| with st.form("prediction_form"): | |
| Product_Weight = st.number_input("Product Weight", value=12.66, format="%.2f") | |
| Product_Allocated_Area = st.number_input("Product Allocated Area", value=0.05, format="%.3f") | |
| Product_MRP = st.number_input("Product MRP", value=150.00, format="%.2f") | |
| Store_Establishment_Year = st.number_input("Store Establishment Year", value=2009, min_value=1900, max_value=2100) | |
| Product_Sugar_Content = st.selectbox("Product Sugar Content", ["Low Sugar","Regular","No Sugar"]) | |
| Product_Type = st.selectbox("Product Type", ["Fruits and Vegetables","Snack Foods","Frozen Foods","Dairy","Household", | |
| "Baking Goods","Canned","Health and Hygiene","Meat","Soft Drinks", | |
| "Breads","Hard Drinks","Others","Starchy Foods","Breakfast","Seafood"]) | |
| Store_Size = st.selectbox("Store Size", ["Small","Medium","High"]) | |
| 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 Type1","Supermarket Type2","Food Mart"]) | |
| submit = st.form_submit_button("Predict") | |
| if submit: | |
| payload = { | |
| "Product_Weight": float(Product_Weight), | |
| "Product_Allocated_Area": float(Product_Allocated_Area), | |
| "Product_MRP": float(Product_MRP), | |
| "Store_Establishment_Year": int(Store_Establishment_Year), | |
| "Product_Sugar_Content": Product_Sugar_Content, | |
| "Product_Type": Product_Type, | |
| "Store_Size": Store_Size, | |
| "Store_Location_City_Type": Store_Location_City_Type, | |
| "Store_Type": Store_Type | |
| } | |
| try: | |
| response = requests.post(BACKEND_URL, json=payload, timeout=60) | |
| if response.status_code == 200: | |
| result = response.json() | |
| st.success(f"Predicted Sales: {result['predictions'][0]:,.2f}") | |
| else: | |
| st.error(f"Error: {response.status_code}") | |
| st.text(response.text) | |
| except Exception as e: | |
| st.error(f"Connection Error: {e}") |