Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import requests | |
| import pandas as pd | |
| st.set_page_config(page_title="SuperKart Sales Prediction", layout="centered") | |
| st.title("SuperKart Sales Forecaster") | |
| # --- Input fields --- | |
| st.subheader("Enter Product & Store Information") | |
| product_weight = st.number_input("Product Weight (kg)", min_value=0.0, step=0.1) | |
| sugar_content = st.selectbox("Product Sugar Content", ["Low", "Medium", "Regular", "High"]) | |
| product_area = st.number_input("Allocated Display Area (sq.m)", min_value=0.01, step=0.01) | |
| product_type = st.selectbox( | |
| "Product Type", | |
| ["Baking Goods", "Canned", "Dairy", "Frozen Foods", "Health and Hygiene", | |
| "Household", "Meat", "Others", "Snack Foods", "Soft Drinks", "Starchy Foods"] | |
| ) | |
| product_mrp = st.number_input("Product MRP (₹)", min_value=1.0, max_value=1000.0, step=1.0) | |
| store_year = st.number_input("Store Establishment Year", min_value=1990, max_value=2025, step=1) | |
| store_size = st.selectbox("Store Size", ["Small", "Medium", "High"]) | |
| store_location = st.selectbox("City Type", ["Tier 1", "Tier 2", "Tier 3"]) | |
| store_type = st.selectbox("Store Type", ["Supermarket Type1", "Supermarket Type2", "Supermarket Type3", "Grocery Store"]) | |
| # --- Construct JSON --- | |
| input_data = { | |
| "Product_Weight": product_weight, | |
| "Product_Sugar_Content": sugar_content, | |
| "Product_Allocated_Area": product_area, | |
| "Product_Type": product_type, | |
| "Product_MRP": product_mrp, | |
| "Store_Establishment_Year": store_year, | |
| "Store_Size": store_size, | |
| "Store_Location_City_Type": store_location, | |
| "Store_Type": store_type | |
| } | |
| # --- Submit to API --- | |
| if st.button("Predict Sales"): | |
| try: | |
| response = requests.post( | |
| "https://huggingface.co/spaces/283nawdeep/superkart-backend/predict", | |
| json=input_data | |
| ) | |
| result = response.json() | |
| if "Predicted_Sales" in result: | |
| st.success(f"Predicted Sales: ₹ {result['Predicted_Sales']}") | |
| else: | |
| st.error(f"Error: {result.get('error', 'No prediction returned')}") | |
| except Exception as e: | |
| st.error(f"API request failed: {e}") | |