Spaces:
Runtime error
Runtime error
| import streamlit as st | |
| import requests | |
| import pandas as pd | |
| # Backend API URL | |
| BACKEND_URL = "https://sastrysagi-SuperKartBackEnd.hf.space" # Replace with actual backend URL | |
| st.title("SuperKart Sales Forecasting System") | |
| # Single prediction form | |
| st.header("Single Prediction") | |
| with st.form("single_prediction_form"): | |
| st.subheader("Enter Product and Store Details") | |
| product_weight = st.number_input("Product Weight", min_value=0.0, value=10.0, 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 (Ratio)", min_value=0.0, value=0.1, step=0.01) | |
| product_type = st.selectbox("Product Type", [ | |
| "Meat", "Snack Foods", "Hard Drinks", "Dairy", "Canned", "Soft Drinks", | |
| "Health and Hygiene", "Baking Goods", "Bread", "Breakfast", "Frozen Foods", | |
| "Fruits and Vegetables", "Household", "Seafood", "Starchy Foods", "Others" | |
| ]) | |
| product_mrp = st.number_input("Product MRP", min_value=0.0, value=100.0, step=1.0) | |
| store_establishment_year = st.number_input("Store Establishment Year", min_value=1900, max_value=2025, value=2000, step=1) | |
| store_size = st.selectbox("Store Size", ["High", "Medium", "Low"]) | |
| store_location_city_type = st.selectbox("Store Location City Type", ["Tier 1", "Tier 2", "Tier 3"]) | |
| store_type = st.selectbox("Store Type", ["Departmental Store", "Supermarket Type1", "Supermarket Type2", "Food Mart"]) | |
| submitted = st.form_submit_button("Predict Sales") | |
| if submitted: | |
| input_data = { | |
| "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_Establishment_Year": store_establishment_year, | |
| "Store_Size": store_size, | |
| "Store_Location_City_Type": store_location_city_type, | |
| "Store_Type": store_type | |
| } | |
| try: | |
| response = requests.post(f"{BACKEND_URL}/v1/sales", json=input_data) | |
| if response.status_code == 200: | |
| st.success(f"Predicted Sales: ${response.json()['Predicted_Sales']:.2f}") | |
| else: | |
| st.error(f"Prediction Error: {response.json().get('error', 'Unknown error')}") | |
| except Exception as e: | |
| st.error(f"Connection Error: {str(e)}") | |
| # Batch prediction | |
| st.header("Batch Prediction") | |
| st.write("Upload a CSV file with columns matching the input features.") | |
| uploaded_file = st.file_uploader("Choose a CSV file", type="csv") | |
| if uploaded_file is not None: | |
| try: | |
| response = requests.post(f"{BACKEND_URL}/v1/salesbatch", files={"file": uploaded_file}) | |
| if response.status_code == 200: | |
| st.subheader("Batch Prediction Results") | |
| st.json(response.json()) | |
| else: | |
| st.error(f"Batch Prediction Error: {response.json().get('error', 'Unknown error')}") | |
| except Exception as e: | |
| st.error(f"Connection Error: {str(e)}") | |