import streamlit as st import pandas as pd import requests # Set the title of the Streamlit app st.title("SuperKart Sales Prediction") # Section for online prediction st.subheader("Sales Prediction") Product_Weight = st.number_input("Product Weight", min_value=0.01, value=16.54) Product_Sugar_Content = st.selectbox("Sugar Content", ["Low Sugar", "Regular", "No Sugar", "reg"], index=0) Product_Allocated_Area = st.number_input("Product Allocated area", value=0.144) Product_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'], index=1) Product_MRP = st.number_input("Product MRP", value=171.43) Store_Id = st.selectbox("Select Store", ['OUT004', 'OUT003', 'OUT001', 'OUT002'], index=1) Store_Establishment_Year = st.number_input("Store Establishment year", value=1999) Store_Size = st.selectbox("Select Store Size", ['Medium', 'High', 'Small'], index=0) Store_Location_City_Type = st.selectbox("Select Store Location", ['Tier 2', 'Tier 1', 'Tier 3'], index=1) Store_Type = st.selectbox("Store Type", ['Supermarket Type2', 'Departmental Store', 'Supermarket Type1', 'Food Mart'], index=1) # Convert user input into a DataFrame input_data = pd.DataFrame([{ "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_Establishment_Year" : Store_Establishment_Year, "Store_Size" : Store_Size, "Store_Location_City_Type" : Store_Location_City_Type, "Store_Type" : Store_Type }]) # Make prediction when the "Predict" button is clicked if st.button("Predict"): response = requests.post("https://codingbuddy-superkartbackendapi.hf.space/v1/sales", json=input_data.to_dict(orient='records')[0]) # Send data to Flask API if response.status_code == 200: prediction = response.json()['Predicted_Sale'] st.success(f"Predicted Sales: {prediction}") else: st.error("Error making prediction.")