import streamlit as st import pandas as pd import requests import json # Set the title of the Streamlit app st.title("SuperKart Sales Prediction") # Section for online prediction st.subheader("Predict Single Product Sales") # Collect user input for product and store features product_id = st.text_input("Product ID", value="FD6114") product_weight = st.number_input("Product Weight", min_value=0.0, value=12.66, step=0.1) product_sugar_content = st.selectbox("Product Sugar Content", ["Low Sugar", "Regular", "No Sugar", "reg"]) product_allocated_area = st.number_input("Product Allocated Area", min_value=0.0, value=0.027, step=0.001) product_type = st.selectbox("Product Type", ['Frozen Foods', 'Dairy', 'Canned', 'Baking Goods', 'Health and Hygiene', 'Household', 'Meat', 'Soft Drinks', 'Breads', 'Hard Drinks', 'Others', 'Starchy Foods', 'Breakfast', 'Seafood', 'Fruits and Vegetables', 'Snack Foods']) product_mrp = st.number_input("Product MRP", min_value=0.0, value=117.08, step=0.01) store_id = st.selectbox("Store ID", ["OUT004", "OUT003", "OUT001", "OUT002"]) store_establishment_year = st.number_input("Store Establishment Year", min_value=1900, max_value=2025, value=2009, step=1) store_size = st.selectbox("Store Size", ["Medium", "High", "Small"]) store_location_city_type = st.selectbox("Store Location City Type", ["Tier 2", "Tier 1", "Tier 3"]) store_type = st.selectbox("Store Type", ["Supermarket Type2", "Departmental Store", "Supermarket Type1", "Food Mart"]) # Convert user input into a dictionary input_data = { "Product_Id": product_id, "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 } # Make prediction when the "Predict" button is clicked if st.button("Predict"): # Replace with your actual Hugging Face Space backend URL backend_url = "https://retheesh-superkartsalesprediction.hf.space/predict_sales" # Replace with your space URL and endpoint try: response = requests.post(backend_url, json=input_data) if response.status_code == 200: prediction = response.json().get('predicted_sales') if prediction is not None: st.success(f"Predicted Product Store Sales Total: {prediction:.2f}") else: st.error("Prediction not found in the response.") st.json(response.json()) # Display the full response for debugging else: st.error(f"Error predicting sales. Status code: {response.status_code}") st.write("Response body:", response.text) # Display response text for debugging st.json(response.json()) # Display response json for debugging except requests.exceptions.RequestException as e: st.error(f"Error connecting to the backend API: {e}")