Spaces:
Sleeping
Sleeping
| import streamlit as st, requests | |
| from datetime import datetime | |
| st.title("SuperKart — Sales Revenue Predictor") | |
| BACKEND_URL = "https://mukherjee78-superkart-backend.hf.space/predict" | |
| product_id = st.text_input("Product ID (e.g., FD6114)") | |
| product_weight = st.number_input("Product Weight (kg)", min_value=0.0, step=0.1) | |
| product_allocated_area = st.number_input("Product Allocated Area (0–1)", min_value=0.0, max_value=1.0, step=0.01) | |
| product_mrp = st.number_input("Product MRP (₹)", min_value=0.0, step=0.5) | |
| product_sugar_content = st.selectbox("Product Sugar Content", ["Low Sugar","Regular","No Sugar","reg"]) | |
| product_type = st.selectbox("Product Type", ["Frozen Foods","Dairy","Canned","Baking Goods","Health and Hygiene", | |
| "Snack Foods","Meat","Household","Hard Drinks","Fruits and Vegetables", | |
| "Breads","Soft Drinks","Breakfast","Others","Starchy Foods","Seafood"]) | |
| store_id = st.selectbox("Store ID", ["OUT004","OUT003","OUT001","OUT002"]) | |
| store_size = st.selectbox("Store Size", ["Small","Medium","High"]) | |
| store_location_city_type = st.selectbox("City Tier", ["Tier 1","Tier 2","Tier 3"]) | |
| store_type = st.selectbox("Store Type", ["Departmental Store","Supermarket Type1","Supermarket Type2","Food Mart"]) | |
| store_establishment_year = st.number_input("Store Establishment Year", min_value=1900, max_value=datetime.now().year, value=2005, step=1) | |
| if st.button("Predict"): | |
| if not product_id: | |
| st.error("Please enter Product ID.") | |
| else: | |
| 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_establishment_year), | |
| "Store_Size": store_size, | |
| "Store_Location_City_Type": store_location_city_type, | |
| "Store_Type": store_type, | |
| "Store_Age": datetime.now().year - int(store_establishment_year), | |
| "Product_Prefix": product_id[:2], | |
| } | |
| try: | |
| r = requests.post(BACKEND_URL, json=payload, timeout=60) | |
| if r.status_code == 200: | |
| st.success(f"Estimated Sales Revenue: ₹{r.json().get('prediction', 0):,.2f}") | |
| else: | |
| st.error(f"Backend error {r.status_code}: {r.text}") | |
| except Exception as e: | |
| st.error(f"Request failed: {e}") | |