File size: 3,185 Bytes
a8ead6d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
05637c2
a8ead6d
 
 
 
 
 
 
 
 
 
 
 
 
05637c2
a8ead6d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e475cbe
 
 
a8ead6d
05637c2
e475cbe
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
import streamlit as st
import pandas as pd
import requests

# Title
st.title("Retail Sales Prediction")

# ---------------------------
# Section: Online Prediction
# ---------------------------
st.subheader("Online Prediction")

# Collect user input
Store_Establishment_Year = st.number_input("Store Establishment Year", min_value=1900, max_value=2100, value=2000)
Product_MRP = st.number_input("Product MRP", min_value=0.0, value=100.0, step=1.0)
Product_Weight = st.number_input("Product Weight", min_value=0.0, value=10.0, step=0.1)
Store_Id = st.selectbox("Store ID", ["OUT004", "OUT001", "OUT003", "OUT002"])
Product_Type = st.selectbox("Product Type", [
    "Fruits and Vegetables", "Snack Foods", "Frozen Foods", "Dairy",
    "Household", "Baking Goods", "Canned", "Health and Hygiene", "Meat",
    "Soft Drinks", "Breads", "Hard Drinks", "Others", "Starchy Foods",
    "Breakfast", "Seafood"
])
Product_Sugar_Content = st.selectbox("Product Sugar Content", ["Low Sugar", "Regular", "No Sugar", "reg"])
Store_Location_City_Type = st.selectbox("Store Location City Type", ["Tier 2", "Tier 1", "Tier 3"])
Store_Size = st.selectbox("Store Size", ["Medium", "High", "Small"])
Product_Allocated_Area = st.number_input("Product Allocated Area", min_value=0.0, value=50.0, step=1.0)
Product_Id = st.text_input("Product ID (Unique Code)", "FD6114")
Store_Type = st.selectbox("Store Type", ["Supermarket Type2", "Supermarket Type1", "Departmental Store", "Food Mart"])

# Convert user input into DataFrame
input_data = pd.DataFrame([{
    'Store_Establishment_Year': Store_Establishment_Year,
    'Product_MRP': Product_MRP,
    'Product_Weight': Product_Weight,
    'Store_Id': Store_Id,
    'Product_Type': Product_Type,
    'Product_Sugar_Content': Product_Sugar_Content,
    'Store_Location_City_Type': Store_Location_City_Type,
    'Store_Size': Store_Size,
    'Product_Allocated_Area': Product_Allocated_Area,
    'Product_Id': Product_Id,
    'Store_Type': Store_Type
}])

# Call backend for prediction
if st.button("Predict Sales"):
    response = requests.post(
        "https://Quantum9999-RetailSlesPredictionBackend.hf.space/v1/sales",
        json=input_data.to_dict(orient='records')[0]
    )
    if response.status_code == 200:
        prediction = response.json()['Predicted_Sales']
        st.success(f"Predicted Sales: {prediction}")
    else:
        st.error("Error making prediction.")

# ---------------------------
# Section: Batch Prediction
# ---------------------------
st.subheader("Batch Prediction")

uploaded_file = st.file_uploader("Upload CSV file for batch prediction", type=["csv"])

if uploaded_file is not None:
    if st.button("Predict Batch Sales"):
        response = requests.post(
            "https://Quantum9999-RetailSlesPredictionBackend.hf.space/v1/salesbatch",
            files={"file": uploaded_file}
        )
        if response.status_code == 200:
          predictions = response.json()  # This is a dict of {id: prediction}
          st.success("Batch predictions completed!")
          st.write(predictions)          # Display all predictions
        else:
          st.error(f"Error making prediction: {response.text}")