import streamlit as st import pandas as pd import requests # Set the title of the Streamlit app st.title("SuperKart's Deceison Making Model") # Section for online prediction st.subheader("Online SuperKart's Model") # Collect user input for property features # Product features product_weight = st.number_input("Product Weight (in grams)", min_value=0.0, step=0.1) product_sugar_content = st.selectbox( "Product Sugar Content", ["Low Sugar", "Regular", "No Sugar"] ) product_allocated_area = st.number_input( "Producted Allocated Area (sq. ft.)", min_value=0.01, step=0.01, value=0.01 ) product_type = st.selectbox( "Product Type", [ "Meat", "Snack Foods", "Hard Drinks", "Dairy", "Canned", "Soft Drinks", "Health and Hygiene", "Baking Goods", "Bread", "Breakfast", "Frozen Foods", "Fruits and Vegetables", "Household", "Seafood", "Starchy Foods", "Others" ] ) product_mrp = st.number_input( "Product MRP (in dollars)", min_value=1.0, step=0.5, value=10.0 ) store_size = st.selectbox( "Store Size", ["Low", "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", "Food Mart", "Supermarket Type1", "Supermarket Type2"] ) # 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 }]) # Make prediction when the "Predict" button is clicked if st.button("Predict"): print(input_data.to_dict(orient='records')[0]) # Send the input data to the Flask API for prediction response = requests.post("https://anithajk-SuperKartDecesionMakingModelBackend.hf.space/v1/productsale", json=input_data.to_dict(orient='records')[0]) # Send data to Flask API if response.status_code == 200: print(f"result {response.json()}") data = response.json() print(data.keys()) prediction = response.json()['Total Revenue (in dollars)'] st.success(f"Total Revenue (in dollars): {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 CSV file for batch prediction", type=["csv"]) # Make batch prediction when the "Predict Batch" button is clicked if uploaded_file is not None: if st.button("Predict Batch"): response = requests.post("https://anithajk-SuperKartDecesionMakingModelBackend.hf.space/v1/productsalebatch", files={"file": uploaded_file}) # Send file to Flask API if response.status_code == 200: predictions = response.json() st.success("Batch predictions completed!") st.write(predictions) # Display the predictions else: st.error("Error making batch prediction.")