File size: 3,160 Bytes
f1c5264
fb8a0ad
 
 
bfa1029
 
 
fb8a0ad
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import pandas as pd
import requests

# Set the Streamlit home directory to a writable location (/tmp)
os.environ["STREAMLIT_HOME"] = "/tmp"

# Set the title of the Streamlit app
st.title("SuperKart Sales Forecasting")

# Section for online prediction
st.subheader("Online Prediction")

# Collect user input for Product and Store features
product_weight = st.number_input("Product Weight (in Grams)", min_value=0.0, step=0.1, value=1.0)
product_sugar_content = st.selectbox("Product Sugar Content", ["Low Sugar", "No Sugar", "Regular"])
product_allocated_area = st.number_input("Product Allocated Display Area (as proportion)", min_value=0.0, max_value=1.0, step=0.01, value=0.1)
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 (in dollars)", min_value=0.0, step=0.01, value=10.0)
store_size = st.selectbox("Store Size", ["Small", "Medium", "High"])
store_location_city_type = st.selectbox("Store Location Type", ["Tier 1", "Tier 2", "Tier 3"])
store_type = st.selectbox("Store Type", ["Departmental Store", "Supermarket Type 1", "Supermarket Type 2", "Food Mart"])
store_age = st.number_input("Store Age (in years)", min_value=0, step=1, value=10)

# Convert user input into a DataFrame
input_data = pd.DataFrame([{
    '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
}])

# Make prediction when the "Predict" button is clicked
if st.button("Predict"):
    response = requests.post("https://donnymv-superkartsalesforecasterbackend.hf.space/v1/sales/predict", json=input_data.to_dict(orient='records')[0])  # Send data to Flask API
    if response.status_code == 200:
        prediction = response.json()['Predicted Sales Revenue (in dollars)']
        st.success(f"Predicted Sales Revenue (in dollars): {prediction}")
    else:
        st.error("Error making prediction.")

# 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://donnymv-superkartsalesforecasterbackend.hf.space/v1/salesbatch/predict", 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.")