Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import requests | |
| import pandas as pd | |
| # Configure page | |
| st.set_page_config(page_title="SuperKart Sales Estimator", layout="centered") | |
| st.title("SuperKart Sales Forecast Tool") | |
| # Input form | |
| st.subheader("Provide Product & Store Information") | |
| col_left, col_right = st.columns(2) | |
| with col_left: | |
| #product_id = st.text_input("Product ID", value="P0001") | |
| weight = st.number_input("Product Weight (in kg)", min_value=0.0, step=0.1, value=1.0) | |
| sugar_level = st.selectbox("Sugar Content", ["Low", "Medium", "Regular", "reg"]) | |
| allocated_area = st.number_input("Display Area (sq.m)", min_value=0.01, step=0.01, value=1.5) | |
| category = st.selectbox("Category", [ | |
| "Baking Goods", "Canned", "Dairy", "Frozen Foods", "Health and Hygiene", | |
| "Household", "Meat", "Others", "Snack Foods", "Soft Drinks", "Starchy Foods" | |
| ]) | |
| mrp = st.number_input("MRP ($)", min_value=1.0, max_value=1000.0, step=1.0, value=100.0) | |
| with col_right: | |
| #store_id = st.text_input("Store ID", value="S0001") | |
| establishment_year = st.number_input("Year Store Opened", min_value=1990, max_value=2025, step=1, value=2010) | |
| store_size = st.selectbox("Store Size", ["Small", "Medium", "High"]) | |
| city_tier = st.selectbox("Location Tier", ["Tier 1", "Tier 2", "Tier 3"]) | |
| store_format = st.selectbox("Store Type", ["Supermarket Type1", "Supermarket Type2", "Supermarket Type3", "Grocery Store"]) | |
| # Create JSON payload | |
| payload = { | |
| #"Product_ID": product_id, | |
| "Product_Weight": weight, | |
| "Product_Sugar_Content": sugar_level, | |
| "Product_Allocated_Area": allocated_area, | |
| "Product_Type": category, | |
| "Product_MRP": mrp, | |
| #"Store_ID": store_id, | |
| "Store_Establishment_Year": establishment_year, | |
| "Store_Size": store_size, | |
| "Store_Location_City_Type": city_tier, | |
| "Store_Type": store_format | |
| } | |
| # Button to call API | |
| if st.button("Get Sales Prediction"): | |
| with st.spinner("Processing your request..."): | |
| try: | |
| api_url = "https://mohith96-SuperKartBackend.hf.space/predict" | |
| response = requests.post(api_url, json=payload, timeout=10) | |
| if response.status_code == 200: | |
| result = response.json() | |
| predicted_value = result.get("Predicted_Sales") or result.get("Predicted_Sales_Product") | |
| if predicted_value is not None: | |
| st.success(f"Predicted Sales: $ {predicted_value:.2f}") | |
| else: | |
| st.warning(f"Unexpected response format: {result}") | |
| else: | |
| st.error(f"API returned {response.status_code}: {response.text}") | |
| except requests.exceptions.RequestException as req_err: | |
| st.error(f"API request failed: {req_err}") | |
| except Exception as error: | |
| st.error(f"Unexpected error: {error}") | |