import requests import streamlit as st import pandas as pd st.title ("SuperKart Product & Store Input Form") st.write ("Predict sales for SuperKart based on product and store details.") # ============================== # Section 1: Product Details # ============================== st.subheader ("Product Details") prod_weight = st.number_input ("Weight in Units (0.0 to 200.0)", min_value=0.0, max_value=200.0, value=23.0, step=0.1) prod_alloc_area = st.number_input ("Allocated Area (fraction 0-1)", min_value=0.0, max_value=1.0, value=0.068) prod_mrp = st.number_input ("MRP in Rupees (0.0 to 1000.0)", min_value=0.0, max_value=1000.0, value=147.0) prod_sug_content = st.selectbox ("Sugar Content", ['Low Sugar', 'Regular', 'No Sugar']) prod_type = st.selectbox ("Product Type", [ 'Frozen Foods', 'Dairy', 'Canned', 'Baking Goods', 'Health and Hygiene', 'Snack Foods', 'Meat', 'Household', 'Hard Drinks', 'Fruits and Vegetables', 'Breads', 'Soft Drinks', 'Breakfast', 'Others', 'Starchy Foods', 'Seafood' ]) # ============================== # Section 2: Store Details # ============================== st.subheader ("Store Details") store_id = st.selectbox ("Store Id", ['OUT001', 'OUT002', 'OUT003', 'OUT004']) store_size = st.selectbox ("Store Size", ['Small', 'Medium', 'High']) store_city_type = st.selectbox ("Type of City", ['Tier 1', 'Tier 2', 'Tier 3']) store_type = st.selectbox ("Store Type", ['Food Mart', 'Departmental Store', 'Supermarket Type1', 'Supermarket Type2']) # ========================== # Single Value Prediction # ========================== #if st.button("Predict", type='primary'): if st.button("Predict Single Product"): # extract the data collected into a structure input_data = { 'Product_Weight' : float (prod_weight), 'Product_Sugar_Content' : prod_sug_content, 'Product_Allocated_Area' : float(prod_alloc_area), 'Product_Type' : prod_type, 'Product_MRP' : float(prod_mrp), 'Store_Id' : store_id, 'Store_Size' : store_size, 'Store_Location_City_Type' : store_city_type, 'Store_Type' : store_type } response = requests.post ( "https://harishsohani-SuperKartBackEnd.hf.space/v1/SuperKartSales", json=input_data ) if response.status_code == 200: ## get result as json result = response.json () ## Get Sales Prediction Value sales_prediction = result.get ("SalesPrediction") # Extract only the value ## format and print predicted value with 2 decimals st.success (f"The predicted sales for given input is Rupees {sales_prediction:.2f}") else: st.error (f"Error processing request- Status Code : {response.status_code}") # ============================== # Batch Prediction # ============================== st.subheader ("Batch Prediction of SuperKart Sales") file = st.file_uploader ("Upload CSV file", type=["csv"]) if file is not None and st.button("Predict Batch"): inputfile = {"file": (file.name, file.getvalue(), "text/csv")} response = requests.post( "https://harishsohani-SuperKartBackEnd.hf.space/v1/SuperKartBatchSales", files=inputfile ) if response.status_code == 200: result = response.json () # convert dict to dataframe for better display result_df = pd.DataFrame(list(result.items()), columns=["Product_Id", "Predicted_Sales"]) st.dataframe (result_df) else: st.error (f"Error in API request {response.status_code}")