File size: 4,275 Bytes
727990e
 
 
 
 
 
 
f3bfcf9
 
727990e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import streamlit as st
import requests
import json
import pandas as pd

# Define the backend API URL
# Replace with the actual URL of your deployed backend API
BACKEND_API_URL_SINGLE = "https://dpanchali-SuperKart-Backend.hf.space/predict_single"
BACKEND_API_URL_BATCH = "https://dpanchali-SuperKart-Backend.hf.space/predict_batch"


st.title("SuperKart Sales Forecasting")

st.write("This application forecasts the sales revenue for product-store combinations.")

# Option to choose between single prediction and batch prediction
prediction_mode = st.radio("Select Prediction Mode:", ("Single Prediction", "Batch Prediction"))

if prediction_mode == "Single Prediction":
    st.header("Predict Sales for a Single Item")

    # Input fields for product and store details
    product_id = st.text_input("Product ID")
    product_weight = st.number_input("Product Weight", min_value=0.0)
    product_sugar_content = st.selectbox("Product Sugar Content", ['Low Sugar', 'Regular', 'No Sugar'])
    product_allocated_area = st.number_input("Product Allocated Area", min_value=0.0)
    product_type = st.selectbox("Product Type", ['Frozen Foods', 'Dairy', 'Canned', 'Baking Goods', 'Health and Hygiene', 'Snack Foods', 'Meat', 'Hard Drinks', 'Fruits and Vegetables', 'Breads', 'Soft Drinks', 'Breakfast', 'Others', 'Starchy Foods', 'Seafood', 'Household'])
    product_mrp = st.number_input("Product MRP", min_value=0.0)
    store_id = st.selectbox("Store ID", ['OUT004', 'OUT003', 'OUT001', 'OUT002'])
    store_establishment_year = st.number_input("Store Establishment Year", min_value=1900, max_value=2024)
    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'])


    if st.button("Predict Sales"):
        # Prepare data for the API request
        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
        }

        # Send POST request to the backend API
        response = requests.post(BACKEND_API_URL_SINGLE, json=input_data)

        # Display the prediction result
        if response.status_code == 200:
            prediction = response.json()['predicted_sales']
            st.success(f"Predicted Sales: {prediction:.2f}")
        else:
            st.error(f"Error: {response.status_code} - {response.text}")

elif prediction_mode == "Batch Prediction":
    st.header("Predict Sales for a Batch of Items")
    st.write("Upload a CSV file with product and store details.")

    uploaded_file = st.file_uploader("Choose a CSV file", type="csv")

    if uploaded_file is not None:
        try:
            # Read the uploaded CSV file into a DataFrame
            input_df = pd.read_csv(uploaded_file)
            st.write("Uploaded Data:")
            st.dataframe(input_df)

            if st.button("Predict Sales (Batch)"):
                 # Send POST request to the backend API with the CSV file
                files = {'file': uploaded_file.getvalue()}
                response = requests.post(BACKEND_API_URL_BATCH, files=files)

                # Display the prediction result
                if response.status_code == 200:
                    predictions = response.json()['predicted_sales']
                    # Display predictions in a DataFrame
                    predictions_df = pd.DataFrame({'Predicted_Sales': predictions})
                    st.write("Predicted Sales:")
                    st.dataframe(predictions_df)
                else:
                    st.error(f"Error: {response.status_code} - {response.text}")

        except Exception as e:
            st.error(f"Error processing file: {e}")