import streamlit as st import pandas as pd import requests # Set the title of the Streamlit app st.title("Sales Prediction") # Collect user input, default value as average of provided values, or alphabetical order product_weight = st.number_input("Weight of the product", min_value=0.0, value=12.0) product_allocated_area = st.number_input("Product Allocated Area",min_value=0.0,value=0.068,step=0.001,format="%.3f") product_mrp = st.number_input("Product MRP", min_value=1.0, step=1.0, value=147.0) store_establishment_year = st.selectbox("Store Establishment Year", [1987, 1998, 1999, 2009]) product_sugar_content = st.selectbox("Product Sugar Content", ["Low Sugar", "No Sugar", "Regular"]) 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"]) store_id = st.selectbox("Store ID", ["OUT004", "OUT003", "OUT001","OUT002"]) 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", "Food Mart", "Supermarket Type1", "Supermarket Type2"]) # Create input dictionary input_data = { 'Product_Weight': product_weight, 'Product_Allocated_Area': product_allocated_area, 'Product_MRP': product_mrp, 'Store_Establishment_Year': store_establishment_year, 'Product_Sugar_Content': product_sugar_content, 'Product_Type': product_type, 'Store_Id': store_id, '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"): try: response = requests.post( "https://maddykan101-SalesPredictionBackend.hf.space/v1/prediction", json=input_data ) if response.status_code == 200: prediction = response.json()['Predicted Sales '] # Adjust key if needed st.success(f"Predicted Sales: {prediction}") else: st.error(f"Prediction failed: {response.status_code}") st.error(f"Prediction failed--: {response}") except Exception as e: st.error(f"An error occurred: {str(e)}")