File size: 3,615 Bytes
30c89a7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47b5e26
30c89a7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47b5e26
30c89a7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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

# import
import streamlit as st
import pandas as pd
import requests

# Streamlit UI
st.title("SuperKart Sales Prediction App")
st.write("Predict store sales based on product and store attributes.")

# Numerical Input fields
product_weight = st.number_input("Product Weight", min_value=0.0, step=0.1)
product_allocated_area = st.number_input("Product Allocated Area", min_value=0.0, step=0.1)
product_mrp = st.number_input("Product MRP", min_value=0.0, step=0.1)
store_age = st.number_input("Store Age (in years)", min_value=0, step=1)

# Categorical inputs with options adapted from your data
product_sugar_content = st.selectbox("Product Sugar Content", ["Low Sugar", "Regular", "No Sugar", "reg"])
product_type = st.selectbox(
    "Product Type",['Frozen Foods', 'Dairy', 'Canned', 'Baking Goods', 'Health and Hygiene',
     'Snack Foods', 'Meat', 'Household', 'Hard Drinks', 'Fruits and Vegetables',
     'Breads', 'Soft Drinks', 'Breakfast', 'Others', 'Starchy Foods', 'Seafood'])
store_type = st.selectbox("Store Type",['Supermarket Type2', 'Departmental Store', 'Supermarket Type1', 'Food Mart'])
store_size = st.selectbox("Store Size (1=Small, 2=Medium, 3=Large)",[1, 2, 3])
store_location_city_type = st.selectbox("Store Location City Type (1=Tier 1, 2=Tier 2, 3=Tier 3)",[1, 2, 3])

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
}])


# Predict button
if st.button("Predict"):
    try:
        response = requests.post(
            "https://SujayAery-SuperKartBackend.hf.space/v1/salesprice",
            json=input_data.to_dict(orient='records')[0]
        )
        if response.status_code == 200:
            prediction = response.json().get("Predicted Price", "No prediction returned")
            st.success(f"Predicted Sales Price: {prediction}")
        else:
            st.error("Error making prediction.")
            st.text(response.text)
    except Exception as e:
        st.error(f"Exception occurred: {e}")

# ----------------- 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("PredictBatch"):
        try:
            files = {"file": (uploaded_file.name, uploaded_file, "text/csv")}
            response = requests.post(
                "https://SujayAery-SuperKartBackend.hf.space/v1/salespricebatch",
                files=files
            )
            if response.status_code == 200:
                predictions = response.json()
                st.success("Batch predictions completed!")

                # Convert to DataFrame and display
                df_predictions = pd.DataFrame(predictions)
                st.dataframe(df_predictions)

                # Download button
                csv = df_predictions.to_csv(index=False).encode('utf-8')
                st.download_button(
                    label="Download Predictions as CSV",
                    data=csv,
                    file_name="SuperKart_Predicted_Sales.csv",
                    mime="text/csv"
                )
            else:
                st.error("Error making batch prediction.")
                st.text(response.text)
        except Exception as e:
            st.error(f"Exception occurred: {e}")