File size: 3,220 Bytes
9e68a57
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77

import requests
import streamlit as st
import pandas as pd

# Set page title
st.title("SuperKart Sales Forecast")

st.markdown("Predict the future sales revenue for SuperKart products based on store and product features.")

# --- Single Prediction Section ---
st.subheader("Single Prediction")

# Input fields
Product_Weight = st.number_input("Product Weight (in kg)", min_value=1.0, max_value=50.0, value=12.7)
Product_Allocated_Area = st.number_input("Product Allocated Area (ratio)", min_value=0.001, max_value=0.5, value=0.08)
Product_MRP = st.number_input("Product MRP (Maximum Retail Price)", min_value=10.0, max_value=500.0, value=160.0)
Store_Age = st.number_input("Store Age (years since establishment)", min_value=1, max_value=50, value=5)
Product_Sugar_Content = st.selectbox("Product Sugar Content", ["Low Sugar", "Regular", "No Sugar"])
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"
])
Store_Size = st.selectbox("Store Size", ["High", "Medium", "Low"])
Store_Location_City_Type = st.selectbox("Store Location City Type", ["Tier 1", "Tier 2", "Tier 3"])
Store_Type = st.selectbox("Store Type", ["Departmental Store", "Supermarket Type 1", "Supermarket Type 2", "Food Mart"])
Product_Prefix = st.text_input("Product Prefix (two letters, e.g., 'SN')", value="SN")

# Create JSON payload
data = {
    "Product_Weight": Product_Weight,
    "Product_Allocated_Area": Product_Allocated_Area,
    "Product_MRP": Product_MRP,
    "Store_Age": Store_Age,
    "Product_Sugar_Content": Product_Sugar_Content,
    "Product_Type": Product_Type,
    "Store_Size": Store_Size,
    "Store_Location_City_Type": Store_Location_City_Type,
    "Store_Type": Store_Type,
    "Product_Prefix": Product_Prefix
}

# Predict button
if st.button("Predict Sales", type="primary"):
    try:
        response = requests.post(
            "https://muthuvaidy-backend.hf.space/v1/predict", json=data
        )
        if response.status_code == 200:
            result = response.json()
            st.success(f"Predicted Sales Total: {result['Predicted_Sales_Total']:.2f}")
        else:
            st.error("Error in API request. Please try again.")
    except Exception as e:
        st.error(f"Request failed: {e}")

# --- Batch Prediction Section ---
st.subheader("Batch Prediction")
st.markdown("Upload a CSV file with multiple records for batch predictions.")

file = st.file_uploader("Upload CSV File", type=["csv"])
if file is not None:
    if st.button("Predict Batch Sales", type="primary"):
        try:
            response = requests.post(
                "https://muthuvaidy-backend.hf.space/v1/predict_batch", files={"file": file}
            )
            if response.status_code == 200:
                result = response.json()
                st.success("Batch Prediction Completed!")
                st.write(result)
            else:
                st.error("Error in batch prediction request.")
        except Exception as e:
            st.error(f"Batch request failed: {e}")