import requests import streamlit as st import pandas as pd # Title of the Streamlit app st.title("Product Sales Prediction for Stores") # Section for single product prediction st.subheader("Please fill details below for sales prediction") # Input fields for user to provide single product/store details Product_Weight = st.number_input("Product_Weight (Weight of the product)", min_value=1.0, max_value=50.0,value=10.0) Product_Sugar_Content = st.selectbox("Product_Sugar_Content (Select the sugar content level of the product)", ['Low Sugar','Regular','No Sugar']) Product_Allocated_Area = st.number_input("Product_Allocated_Area (Area allocated for the product)", min_value=0.001,max_value=0.5,value=0.1) Product_Type = st.selectbox("Product_Type (Select the type of product)", ['Fruits and Vegetables','Snack Foods','Frozen Foods','Dairy','Household','Baking Goods','Canned','Health and Hygiene','Meat','Soft Drinks','Breads','Hard Drinks','Others','Starchy Foods','Breakfast','Seafood']) Product_MRP = st.number_input("Product_MRP (Enter the price of the product)", min_value=1.0,max_value=1000.0,value=100.0) Store_Id = st.selectbox("Store_Id (Select the Store ID)", ['OUT001','OUT002','OUT003','OUT004']) Store_Establishment_Year = st.selectbox("Store_Establishment_Year (Select the year the store was established)", [2009,1987,1999,1998]) Store_Size = st.selectbox("Store_Size (Select the store size)", ["Medium", "High","Small"]) Store_Location_City_Type = st.selectbox("Store_Location_City_Type (Select the type of city where the store is located)", ["Tier 2", "Tier 1","Tier 3"]) Store_Type = st.selectbox("Store_Type (Select the type of store)",['Supermarket Type2','Supermarket Type1','Departmental Store','Food Mart']) # Prepare the payload to send to the backend API sales_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_Id': Store_Id, 'Store_Size': Store_Size, 'Store_Location_City_Type': Store_Location_City_Type, } # When the "Predict" button is clicked, send a POST request to the backend API if st.button("Predict", type='primary'): response = requests.post("https://parthipan00410-salespredictionbackend.hf.space/v1/salesdata", json=sales_data) # If the request is successful, display the predicted sales if response.status_code == 200: result = response.json() sales_prediciton = result["predicted_sales"] st.write(f"Here is the predicted sales value for the product: {sales_prediciton}.") else: st.error("Error in API request. Please check the backend or payload format.") # Section for batch prediction st.subheader("Batch Prediction") # File uploader to allow CSV upload for batch prediction file = st.file_uploader("Upload CSV file", type=["csv"]) if file is not None: # When "Predict for Batch" button is clicked, send CSV to backend API if st.button("Predict for Batch", type='primary'): response = requests.post("https://parthipan00410-salespredictionbackend.hf.space/v1/salesdatabatch", files={"file": file}) # Display the batch prediction results if successful if response.status_code == 200: result = response.json() st.header("Batch Prediction Results") st.write(result) else: st.error("Error in API request. Please check the backend or CSV format.")