File size: 2,943 Bytes
88dc0d8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d1a8097
88dc0d8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 requests
import streamlit as st
import pandas as pd

st.title("Sales Forecaster")

# Batch Prediction
st.subheader("Predicting Sales")

# Input fields for product data
Product_Id = st.text_input("Product ID", value="FD6114")
Product_Weight = st.number_input("Product Weight", min_value=0.0, max_value=22.0, format="%.2f")
Product_Sugar_Content = st.selectbox("Product Sugar Content", ["Low Sugar", "Regular", "No Sugar", "reg"])
Product_Allocated_Area = st.number_input("Product Allocated Area (Ratio of Total Area)  ", min_value=0.0, max_value=1.0, format="%.2f")
Product_Type = st.selectbox("Type Of Product", ["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_MRP = st.number_input("Price of Product", min_value=0.0, format="%.2f")
Store_Id = st.selectbox("Store ID", ["OUT004", "OUT001", "OUT003", "OUT002"])
Store_Establishment_Year = st.number_input("Year of Store Establishment", min_value=1800, max_value=2025, value=2008)
Store_Size = st.selectbox("Size of Store", ["High", "Medium", "Small"])
Store_Location_City_Type = st.selectbox("City Tier of the Store", ["Tier 1", "Tier 2", "Tier 3"])
Store_Type = st.selectbox("Type of Store", ["Supermarket Type1", "Supermarket Type2", "Departmental Store", "Food Mart"])

product_data = {
    '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_Id': Store_Id,
    'Store_Establishment_Year': Store_Establishment_Year,
    'Store_Size': Store_Size,
    'Store_Location_City_Type': Store_Location_City_Type,
    'Store_Type': Store_Type
}

if st.button("Predict", type='primary'):
    response = requests.post("https://Anil28053-Backend.hf.space/v1/customer", json=product_data)    # enter user name and space name before running the cell
    if response.status_code == 200:
        result = response.json()
        sales_prediction = result["Prediction"]  # Extract only the value
        st.success(f"Based on the provided info, Product {Product_Id} is forecasted to generate sales of ₹{sales_prediction:.2f}")
    else:
        st.error("Error in API request")

# Batch Prediction
st.subheader("Batch Prediction")

file = st.file_uploader("Upload CSV file", type=["csv"])
if file is not None:
    if st.button("Predict for Batch", type='primary'):
        response = requests.post("https://Anil28053-Backend.hf.space/v1/customerbatch", files={"file": file})    # enter user name and space name before running the cell
        if response.status_code == 200:
            result = response.json()
            st.header("Batch Prediction Results")
            st.write(result)
        else:
            st.error("Error in API request")