File size: 2,707 Bytes
5000ded
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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

import streamlit as st
import requests

st.title("Super Kart Sales Predictor")

# Input fields for product and store data
Product_Weight = st.slider("Product Weight", min_value=0.0, value=12.0, max_value = 22.0)
Product_MRP = st.slider("Product MRP", min_value=30.0, value=145.0, max_value=260.0)
Product_Allocated_Area = st.slider("Product Allocated Area", min_value=0.0, value=0.05, max_value=0.3)
Product_Sugar_Content = st.selectbox("Product Sugar Content", ["Low Sugar", "Regular", "No Sugar"])
Store_Size = st.selectbox("Store Size", ["Small", "Medium", "High"])
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 Type1", "Supermarket Type2", "Food Mart"])
Store_Age_Years = st.slider("Store Age (Years)", min_value=0, value=15, max_value=40)
Product_Id_prefix = st.selectbox("Product ID Prefix", ["FD", "DR", "NC"])
Product_FD_perishable = st.selectbox("Product FD Perishable flag", ["Perishables", "Non Perishables"])

product_data = {
    "Product_Weight": Product_Weight,
    "Product_MRP": Product_MRP,
    "Product_Allocated_Area": Product_Allocated_Area,
    "Product_Sugar_Content": Product_Sugar_Content,
    "Store_Size": Store_Size,
    "Store_Location_City_Type": Store_Location_City_Type,
    "Store_Type": Store_Type,
    "Store_Age_Years": Store_Age_Years,
    "Product_Id_prefix": Product_Id_prefix,
    "Product_FD_perishable": Product_FD_perishable,
}

# Make prediction when the "Predict" button is clicked
if st.button("Predict", type='primary'):
    response = requests.post("https://AlbertoNuin-SuperKartBackend.hf.space/v1/predict", json=product_data)
    if response.status_code == 200:
        result = response.json()
        predicted_sales = result["Sales"]
        st.write(f"Predicted Product Store Sales Total: {predicted_sales:.2f}")
    else:
        st.error("Error in API request")

# Section for batch prediction
st.subheader("Batch Prediction")

# Allow users to upload a CSV file for batch prediction
uploaded_file = st.file_uploader("Upload CSV file for batch prediction", type=["csv"])

# Make batch prediction when the "Predict Batch" button is clicked
if uploaded_file is not None:
    if st.button("Predict Batch"):
        response = requests.post("https://AlbertoNuin-SuperKartBackend.hf.space/v1/batch", files={"file": uploaded_file})  # Send file to Flask API
        if response.status_code == 200:
            predictions = response.json()
            st.success("Batch predictions completed!")
            st.write(predictions)  # Display the predictions
        else:
            st.error("Error making batch prediction.")