| | import streamlit as st |
| | import pandas as pd |
| | import requests |
| | import numpy as np |
| |
|
| | |
| | st.title("🛒 SuperKart Sales Total Predictor") |
| | st.markdown("Forecasting product sales based on product characteristics and store type.") |
| |
|
| | |
| | |
| | API_BASE_URL = "https://Tamilvelan-StoreSalesPredictionBackend.hf.space" |
| | ONLINE_PREDICTION_URL = f"{API_BASE_URL}/v1/sales" |
| | |
| |
|
| |
|
| | |
| | st.subheader("Predict Single Product-Store Sales") |
| |
|
| | |
| |
|
| | |
| | col1, col2 = st.columns(2) |
| | with col1: |
| | product_weight = st.number_input("Product Weight (kg)", min_value=1.0, max_value=25.0, value=12.02, step=0.01) |
| | product_mrp = st.number_input("Product MRP ($)", min_value=10.0, max_value=300.0, value=141.6, step=0.01) |
| | store_age = st.number_input("Store Age (Years)", min_value=1, max_value=50, value=25, help="Calculated as (Current Year - Store Establishment Year)") |
| | |
| | with col2: |
| | |
| | product_sugar_content = st.selectbox("Product Sugar Content", ["Low Sugar", "Regular", "No Sugar"]) |
| | product_type = st.selectbox("Product Type", ['Fruits and Vegetables', 'Snack Foods', 'Soft Drinks', 'Dairy', 'Baking Goods', 'Household', 'Others', 'Meat', 'Frozen Foods', 'Breakfast', 'Canned', 'Starchy Foods', 'Health and Hygiene', 'Fats and Oils', 'Seafood']) |
| | store_type = st.selectbox("Store Type", ['Supermarket Type 1', 'Departmental Store', 'Supermarket Type 2', 'Food Mart']) |
| |
|
| | |
| | |
| | store_size_map = {"Low": 0, "Medium": 1, "High": 2} |
| | store_city_map = {"Tier 3": 1, "Tier 2": 2, "Tier 1": 3} |
| |
|
| | store_size_raw = st.selectbox("Store Size", list(store_size_map.keys())) |
| | store_location_city_type_raw = st.selectbox("Store Location City Type", list(store_city_map.keys())) |
| |
|
| | |
| | |
| | |
| | |
| |
|
| | |
| | product_allocated_area_raw = st.number_input("Product Allocated Area (Raw Value)", min_value=0.0, value=0.05, step=0.01) |
| | product_allocated_area_log = float(np.log1p(product_allocated_area_raw)) |
| |
|
| | |
| |
|
| |
|
| | |
| | input_payload = { |
| | 'Product_Weight': product_weight, |
| | 'Product_MRP': product_mrp, |
| | 'Store_Age': store_age, |
| | 'Product_Allocated_Area_Log': product_allocated_area_log, |
| | |
| | |
| | 'Store_Size_Encoded': store_size_map[store_size_raw], |
| | 'Store_Location_City_Type_Encoded': store_city_map[store_location_city_type_raw], |
| | |
| | |
| | 'Product_Sugar_Content': product_sugar_content, |
| | 'Product_Type': product_type, |
| | 'Store_Type': store_type, |
| | } |
| |
|
| |
|
| | |
| | if st.button("Predict Sales Total"): |
| | try: |
| | |
| | response = requests.post(ONLINE_PREDICTION_URL, json=input_payload) |
| | |
| | if response.status_code == 200: |
| | prediction = response.json().get('Predicted Sales Total (in dollars)') |
| | if prediction is not None: |
| | st.success(f"Predicted Product Sales Total: **${prediction:,.2f}**") |
| | else: |
| | st.error("Prediction key not found in API response.") |
| | else: |
| | st.error(f"Error making prediction. Status code: {response.status_code}. Response: {response.text}") |
| | except requests.exceptions.RequestException as e: |
| | st.error(f"An error occurred while connecting to the API: {e}") |
| |
|