Spaces:
Sleeping
Sleeping
Download app.py from gigcode/SuperKartFrontend: direct link, hf CLI and curl.
- Browser
- Download file 3.01 kB
-
https://huggingface.co/spaces/gigcode/SuperKartFrontend/resolve/main/app.py
- Command line
-
hf download hf://spaces/gigcode/SuperKartFrontend/app.py
-
curl -L -o app.py https://huggingface.co/spaces/gigcode/SuperKartFrontend/resolve/main/app.py
3.01 kB
| import streamlit as st | |
| import requests | |
| from datetime import datetime | |
| # App title and description | |
| st.set_page_config(page_title="SuperKart Sales Forecasting", layout="centered") | |
| st.title("SuperKart Sales Forecasting App") | |
| st.markdown("Enter product and store attributes to forecast monthly product sales revenue.") | |
| st.markdown("*All sales are reported in ($) USD.*") | |
| # --- Input fields for product and store data --- | |
| product_weight = st.number_input("Product Weight (oz)", min_value=0.0, value=12.66, step=0.1) | |
| product_sugar_content = st.selectbox("Product Sugar Content", ["Low Sugar", "Regular", "No Sugar"]) | |
| product_allocated_area = st.number_input("Product Allocated Area (linear in.)", min_value=0.0, value=100.00, step=1.0) | |
| product_mrp = st.number_input("Maximum Retail Price (USD)", min_value=0.0, value=150.00, step=0.5) | |
| 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", ["Supermarket Type1", "Supermarket Type2", "Departmental Store", "Food Mart"]) | |
| store_age_years = st.slider("Store Age (years)", min_value=0, max_value=30, value=10, step=1) | |
| # Product Type categories to match the dataset | |
| product_type_category = st.selectbox( | |
| "Product Type Category", | |
| [ | |
| "Fruits and Vegetables", "Snack Foods", "Household", "Frozen Foods", "Dairy", | |
| "Baking Goods", "Health and Hygiene", "Hard Drinks", "Soft Drinks", "Meat", | |
| "Canned", "Breads", "Breakfast", "Seafood", "Starchy Foods", "Others" | |
| ] | |
| ) | |
| # --- Prepare payload for the backend API --- | |
| current_year = datetime.now().year | |
| payload = { | |
| "Product_Weight": product_weight, | |
| "Product_Sugar_Content": product_sugar_content, | |
| "Product_Allocated_Area": product_allocated_area / 1000, # Normalize based on EDA insights | |
| "Product_MRP": product_mrp, | |
| "Store_Size": store_size, | |
| "Store_Location_City_Type": store_location_city_type, | |
| "Store_Type": store_type, | |
| "Store_Establishment_Year": int(current_year - store_age_years), | |
| "Product_Type": product_type_category | |
| } | |
| # ---- Call backend Space ---- | |
| API_URL = "https://gigcode-superkartbackend.hf.space/v1/sales" | |
| if st.button("Predict", type="primary"): | |
| with st.spinner('Forecasting...'): | |
| try: | |
| resp = requests.post(API_URL, json=payload, timeout=30) | |
| if resp.status_code == 200: | |
| result = resp.json() | |
| predicted_sales = result.get("Predicted Product_Store_Sales_Total", 0) | |
| st.success(f"Predicted Product Store Sales Total: ${float(predicted_sales):,.2f}") | |
| else: | |
| st.error(f"API error [{resp.status_code}]: {resp.text}") | |
| except requests.exceptions.RequestException as e: | |
| st.error(f"Request failed: Could not connect to the API. Please ensure the backend is running. Error: {e}") | |
| except Exception as e: | |
| st.error(f"An unexpected error occurred: {e}") | |