import streamlit as st import requests import pandas as pd st.title(" SuperKart Sales Prediction App") st.write("Predict the **Product_Store_Sales_Total** using Machine Learning!") # ------------------------------ # Single Input Prediction (Online) # ------------------------------ st.header(" Single Prediction") # Input fields Product_Weight = st.number_input("Product Weight", min_value=0.0, step=0.1) Product_Allocated_Area = st.number_input("Allocated Area", min_value=0.0, step=1.0) Product_MRP = st.number_input("Product MRP", min_value=0.0, step=1.0) Store_Establishment_Year = st.number_input("Store Establishment Year", min_value=1900, max_value=2025, value=2010) Store_Size = st.selectbox("Store Size", ["Small", "Medium", "High"]) Store_Location_City_Type = st.selectbox("City Type", ["Tier 3", "Tier 2", "Tier 1"]) Product_Sugar_Content = st.selectbox("Sugar Content", ["Low Sugar", "Regular", "No Sugar"]) Product_Type = st.text_input("Product Type (e.g., Snack Foods)") Store_Type = st.text_input("Store Type (e.g., Supermarket Type 1)") data = { "Product_Weight": Product_Weight, "Product_Allocated_Area": Product_Allocated_Area, "Product_MRP": Product_MRP, "Store_Establishment_Year": Store_Establishment_Year, "Store_Size": Store_Size, "Store_Location_City_Type": Store_Location_City_Type, "Product_Sugar_Content": Product_Sugar_Content, "Product_Type": Product_Type, "Store_Type": Store_Type, } if st.button("Predict Sales"): try: response = requests.post("https://rajanan-backend.hf.space/v1/predict", json=data) if response.status_code == 200: result = response.json() st.success(f" Predicted Sales: {result['Predicted_Product_Store_Sales_Total']}") else: st.error(" Error from API!") except: st.error(" Unable to connect to backend API") # ------------------------------ # Batch Prediction (Upload CSV) # ------------------------------ st.header(" Batch Prediction (Upload CSV)") uploaded_file = st.file_uploader("Upload CSV File", type=['csv']) if uploaded_file: if st.button("Predict Batch Sales"): try: response = requests.post("https://rajanan-backend.hf.space/v1/predict_batch", files={"file": uploaded_file}) if response.status_code == 200: result = pd.read_json(response.text) st.write(result) st.success(" Batch predictions generated!") else: st.error("Error from backend API") except: st.error("Failed to connect to API")