File size: 2,089 Bytes
91fd4b8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53

import streamlit as st
import pandas as pd
import joblib
import requests

# Title
st.title("πŸ›’ SuperKart Sales Forecasting")

st.markdown("Enter product and store details to predict sales.")

# Input fields
product_weight = st.number_input("Product Weight (kg)", min_value=1.0, step=0.1)
product_sugar_content = st.selectbox("Sugar Content", ["Low Sugar", "Regular", "No Sugar", "Sugar Free"])
product_allocated_area = st.slider("Display Area (%)", 0.0, 0.3, 0.05)
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 (β‚Ή)", min_value=10.0, step=1.0)
store_size = st.selectbox("Store Size", ["Small", "Medium", "High"])
store_location_city_type = st.selectbox("City Tier", ["Tier 1", "Tier 2", "Tier 3"])
store_type = st.selectbox("Store Type", [
    "Departmental Store", "Supermarket Type1", "Supermarket Type2", "Food Mart"
])
store_age = st.slider("Store Age (Years)", 1, 40, 15)

# Submit
if st.button("Predict Sales"):
    input_data = {
        "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
    }

    # Call the backend API
    try:
        response = requests.post("https://<your-backend-username>.huggingface.space/<backend-space-name>/predict", json=input_data)
        result = response.json()
        if "predicted_sales" in result:
            st.success(f"πŸ“ˆ Predicted Sales: β‚Ή{result['predicted_sales']}")
        else:
            st.error(f"Error: {result.get('error', 'Unknown')}")
    except Exception as e:
        st.error(f"API call failed: {e}")