%%writefile frontend_files/app.py import streamlit as st import pandas as pd import requests # Set the title of the Streamlit app st.title("SuperKart Product Sales Prediction") # Section for online prediction st.subheader("Online Prediction") # Collect user input for product/store features Product_Weight = st.number_input("Product Weight (kg)", min_value=0.0, value=12.5) Product_Sugar_Content = st.selectbox("Product Sugar Content", ["Low Sugar", "No Sugar", "Regular", "reg"]) Product_Allocated_Area = st.number_input("Allocated Shelf Area", min_value=0.0, value=0.05) Product_Type = st.selectbox("Product Type", [ "Fruits and Vegetables", "Dairy", "Canned", "Baking Goods", "Snack Foods", "Health and Hygiene", "Household", "Frozen Foods", "Meat", "Soft Drinks", "Breads", "Hard Drinks", "Starchy Foods", "Breakfast", "Seafood" ]) Product_MRP = st.number_input("Product MRP (₹)", min_value=0.0, value=150.0) Store_Size = st.selectbox("Store Size", ["Small", "Medium", "High"]) Store_Location_City_Type = st.selectbox("City Type", ["Tier 1", "Tier 2", "Tier 3"]) Store_Type = st.selectbox("Store Type", ["Supermarket Type1", "Supermarket Type2", "Food Mart", "Departmental Store"]) Store_Establishment_Year = st.slider("Store Establishment Year", min_value=1987, max_value=2025, value=2005) Store_Age = 2025 - Store_Establishment_Year # 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_Size': Store_Size, 'Store_Location_City_Type': Store_Location_City_Type, 'Store_Type': Store_Type, 'Store_Age': Store_Age }]) # Make prediction when the "Predict" button is clicked if st.button("Predict"): response = requests.post( "https://PStark-SuperKartSalesPrediction-backend.hf.space/v1/sales", json=input_data.to_dict(orient='records')[0] ) if response.status_code == 200: prediction = response.json()['Predicted Sales (₹)'] st.success(f"🧾 Predicted Product Sales: ₹{prediction}") else: st.error("Error making prediction.") # Section for batch prediction st.subheader("Batch Prediction") # Allow users to upload a CSV file for batch prediction uploaded_file = st.file_uploader("Upload a CSV file for batch sales prediction", type=["csv"]) if uploaded_file is not None: if st.button("Predict Batch"): response = requests.post( "https://PStark-SuperKartSalesPrediction.hf.space/v1/salesbatch", files={"file": uploaded_file} ) if response.status_code == 200: predictions = response.json() st.success("Batch predictions completed!") st.write(predictions) else: st.error("Error making batch prediction.")