# import import streamlit as st import pandas as pd import requests # Streamlit UI st.title("SuperKart Sales Prediction App") st.write("Predict store sales based on product and store attributes.") # Numerical Input fields product_weight = st.number_input("Product Weight", min_value=0.0, step=0.1) product_allocated_area = st.number_input("Product Allocated Area", min_value=0.0, step=0.1) product_mrp = st.number_input("Product MRP", min_value=0.0, step=0.1) store_age = st.number_input("Store Age (in years)", min_value=0, step=1) # Categorical inputs with options adapted from your data product_sugar_content = st.selectbox("Product Sugar Content", ["Low Sugar", "Regular", "No Sugar", "reg"]) 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']) store_type = st.selectbox("Store Type",['Supermarket Type2', 'Departmental Store', 'Supermarket Type1', 'Food Mart']) store_size = st.selectbox("Store Size (1=Small, 2=Medium, 3=Large)",[1, 2, 3]) store_location_city_type = st.selectbox("Store Location City Type (1=Tier 1, 2=Tier 2, 3=Tier 3)",[1, 2, 3]) 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 }]) # Predict button if st.button("Predict"): try: response = requests.post( "https://SujayAery-SuperKartBackend.hf.space/v1/salesprice", json=input_data.to_dict(orient='records')[0] ) if response.status_code == 200: prediction = response.json().get("Predicted Price", "No prediction returned") st.success(f"Predicted Sales Price: {prediction}") else: st.error("Error making prediction.") st.text(response.text) except Exception as e: st.error(f"Exception occurred: {e}") # ----------------- Batch Prediction ----------------- st.subheader("Batch Prediction") uploaded_file = st.file_uploader("Upload CSV file for batch prediction", type=["csv"]) if uploaded_file is not None: if st.button("PredictBatch"): try: files = {"file": (uploaded_file.name, uploaded_file, "text/csv")} response = requests.post( "https://SujayAery-SuperKartBackend.hf.space/v1/salespricebatch", files=files ) if response.status_code == 200: predictions = response.json() st.success("Batch predictions completed!") # Convert to DataFrame and display df_predictions = pd.DataFrame(predictions) st.dataframe(df_predictions) # Download button csv = df_predictions.to_csv(index=False).encode('utf-8') st.download_button( label="Download Predictions as CSV", data=csv, file_name="SuperKart_Predicted_Sales.csv", mime="text/csv" ) else: st.error("Error making batch prediction.") st.text(response.text) except Exception as e: st.error(f"Exception occurred: {e}")