Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import pandas as pd | |
| import requests | |
| # Hugging Face backend API endpoint | |
| API_URL = "https://vallabbharath-Backend.hf.space/predict" | |
| st.set_page_config(page_title="Sales Prediction App", page_icon="ποΈ", layout="wide") | |
| st.title("π Sales Prediction Dashboard") | |
| st.markdown(""" | |
| Upload or enter product and store details below to predict expected sales. | |
| """) | |
| # --- Input Section --- | |
| st.subheader("Enter Input Data") | |
| # You can also adjust these based on your backend model features | |
| col1, col2 = st.columns(2) | |
| with col1: | |
| product_weight = st.number_input("Product Weight", min_value=0.0, step=0.1) | |
| product_sugar = st.selectbox("Product Sugar Content", ['Low Sugar', 'No Sugar', 'Regular', 'reg']) | |
| 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, step=0.1) | |
| product_allocated_area = st.number_input("Product Allocated Area", min_value=0.001, step=0.001) | |
| with col2: | |
| store_id = st.text_input("Store ID") | |
| store_est_year = st.number_input("Store Establishment Year", min_value=1900, max_value=2025, value=2010) | |
| store_size = st.selectbox("Store Size", ['High', 'Medium', 'Small']) | |
| store_loc = 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']) | |
| if st.button("Predict"): | |
| # Prepare data for backend | |
| data = { | |
| "Product_Weight": product_weight, | |
| "Product_Sugar_Content": product_sugar, | |
| "Product_Allocated_Area": product_allocated_area, # if needed, or remove if not used | |
| "Product_Type": product_type, | |
| "Product_MRP": product_mrp, | |
| "Store_Id": store_id, | |
| "Store_Establishment_Year": int(store_est_year), | |
| "Store_Size": store_size, | |
| "Store_Location_City_Type": store_loc, | |
| "Store_Type": store_type | |
| } | |
| try: | |
| response = requests.post(API_URL, json=data) | |
| if response.status_code == 200: | |
| result = response.json() | |
| st.success(f"π’ Predicted Sales: **{result['prediction']:.2f}**") | |
| else: | |
| st.error(f"Backend Error: {response.text}") | |
| except Exception as e: | |
| st.error(f"Error connecting to backend: {e}") | |