File size: 2,987 Bytes
e65f2af
 
 
 
 
 
 
 
 
 
e2adc86
 
 
 
 
 
 
 
 
 
 
 
e65f2af
e2adc86
 
 
 
e65f2af
e2adc86
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e65f2af
 
 
cabed4c
e65f2af
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import pandas as pd
import requests

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

# Section for online prediction
st.subheader("Sales Forecast")

# Define the input fields
product_weight = st.number_input("Product Weight", min_value=0.0)
sugar_content = st.selectbox("Sugar Content", ["Low Sugar", "Regular", "No Sugar", "reg"])
allocated_area = st.number_input("Allocated Area", min_value=0.0)
product_type = st.selectbox("Product Type", sorted([
    "Frozen Foods", "Dairy", "Canned", "Baking Goods", "Health and Hygiene", "Snack Foods",
    "Meat", "Household", "Fruits and Vegetables", "Breads", "Hard Drinks", "Soft Drinks",
    "Breakfast", "Starchy Foods", "Seafood", "Others"
]))
product_mrp = st.number_input("Product MRP", min_value=0.0)
store_id = st.text_input("Store ID")
store_year = st.number_input("Store Establishment Year", min_value=1900, max_value=2100)
store_size = st.selectbox("Store Size", ["Small", "Medium", "High"])
city_type = st.selectbox("City Type", ["Tier 1", "Tier 2", "Tier 3"])
store_type = st.selectbox("Store Type", [
    "Supermarket Type1", "Supermarket Type2", "Departmental Store", "Food Mart"
])

# Collect all inputs into a DataFrame
input_dict = {
    "Product_Weight": product_weight,
    "Product_Sugar_Content": sugar_content,
    "Product_Allocated_Area": allocated_area,
    "Product_Type": product_type,
    "Product_MRP": product_mrp,
    "Store_Id": store_id,
    "Store_Establishment_Year": store_year,
    "Store_Size": store_size,
    "Store_Location_City_Type": city_type,
    "Store_Type": store_type
}

print("Input dict______", input_dict)

input_df = pd.DataFrame([input_dict])

# Make prediction when the "Predict" button is clicked
if st.button("Predict Sales"):
    response = requests.post("https://dutta2arnab-SuperKartSalesPredictionBackend.hf.space/v1/sales_forecast", json=input_df.to_dict(orient='records')[0])  # Send data to Flask API
    if response.status_code == 200:
        prediction = response.json()['Predicted Price (in dollars)']
        st.success(f"Predicted Sales price (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 Sales Batch"):
        response = requests.post("https://dutta2arnab-SuperKartSalesPredictionBackend.hf.space/v1/sales_forecast_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.")