import requests import streamlit as st import pandas as pd st.title("SuperKart Sales Prediction") # Single Item Prediction st.subheader("Single Item Prediction") # Input fields for product and store data based on SuperKart dataset features product_weight = st.number_input("Product Weight", min_value=0.0, value=12.66) product_sugar_content = st.selectbox("Product Sugar Content", ["Low Sugar", "Regular", "No Sugar"]) product_allocated_area = st.number_input("Product Allocated Area", min_value=0.0, value=0.027) product_type = st.selectbox("Product Type", ['Baking Goods', 'Breads', 'Breakfast', 'Canned', 'Dairy', 'Frozen Foods', 'Fruits and Vegetables', 'Hard Drinks', 'Health and Hygiene', 'Household', 'Meat', 'Others', 'Seafood', 'Snack Foods', 'Soft Drinks', 'Starchy Foods']) product_mrp = st.number_input("Product MRP", min_value=0.0, value=117.08) store_id = st.selectbox("Store ID", ['OUT001', 'OUT002', 'OUT003', 'OUT004']) store_establishment_year = st.number_input("Store Establishment Year", min_value=1985, max_value=datetime.now().year, value=2009) store_size = st.selectbox("Store Size", ["Small", "Medium", "High"]) store_location_city_type = st.selectbox("Store Location City Type", ["Tier 1", "Tier 2", "Tier 3"]) store_type = st.selectbox("Store Type", ["Departmental Store", "Supermarket Type1", "Supermarket Type2", "Food Mart"]) item_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_Establishment_Year': store_establishment_year, 'Store_Size': store_size, 'Store_Location_City_Type': store_location_city_type, 'Store_Type': store_type, } # Replace with your Hugging Face Space URL for the backend backend_url = "https://Amittripipathi-SuperKart.hf.space" if st.button("Predict Sales", type='primary'): response = requests.post(f"{backend_url}/v1/predict_sale", json=item_data) if response.status_code == 200: result = response.json() predicted_sales = result["Predicted_Sales"] st.write(f"The predicted sales for this item is: {predicted_sales:.2f}") else: st.error(f"Error in API request: {response.status_code} - {response.text}") # Batch Prediction st.subheader("Batch Prediction") file = st.file_uploader("Upload CSV file for Batch Prediction", type=["csv"]) if file is not None: if st.button("Predict for Batch", type='primary'): response = requests.post(f"{backend_url}/v1/predict_sale_batch", files={"file": file}) if response.status_code == 200: result = response.json() st.header("Batch Prediction Results") # Display batch predictions predictions_df = pd.DataFrame(result['Batch_Predictions'], columns=['Predicted_Sales']) st.dataframe(predictions_df) else: st.error(f"Error in API request: {response.status_code} - {response.text}")