File size: 2,639 Bytes
cf7995e
 
 
 
17c1521
cf7995e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import requests
import streamlit as st
import pandas as pd

st.title("Frontend Prediction")

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

# Input fields for data entry (default values = median from your description)
ID = st.number_input("Customer ID", min_value=1, max_value=5000, value=2500)
Age = st.number_input("Age", min_value=18, max_value=100, value=45)
Experience = st.number_input("Experience (Years)", min_value=-5, max_value=50, value=20)
Income = st.number_input("Annual Income (in $000)", min_value=0, max_value=300, value=64)
ZIPCode = st.number_input("ZIP Code", min_value=90000, max_value=99999, value=93437)
Family = st.selectbox("Family Members", [1, 2, 3, 4], index=1)
CCAvg = st.number_input("Credit Card Avg Monthly Spend", min_value=0.0, max_value=10.0, value=1.5)
Education = st.selectbox("Education Level", [1, 2, 3], index=1)
Mortgage = st.number_input("Mortgage Amount", min_value=0, max_value=1000, value=0)
Securities_Account = st.selectbox("Has Securities Account?", [0, 1], index=0)
CD_Account = st.selectbox("Has CD Account?", [0, 1], index=0)
Online = st.selectbox("Uses Online Banking?", [0, 1], index=1)
CreditCard = st.selectbox("Has Credit Card?", [0, 1], index=0)

# Dictionary for model input
user_input_data = {
    'ID': ID,
    'Age': Age,
    'Experience': Experience,
    'Income': Income,
    'ZIPCode': ZIPCode,
    'Family': Family,
    'CCAvg': CCAvg,
    'Education': Education,
    'Mortgage': Mortgage,
    'Securities_Account': Securities_Account,
    'CD_Account': CD_Account,
    'Online': Online,
    'CreditCard': CreditCard
}

if st.button("Predict", type='primary'):
    response = requests.post("https://kjdeka-test-backend.hf.space/v1/dijakbn", json=user_input_data)    # enter user name and backend space name before running the cell
    if response.status_code == 200:
        result = response.json()
        frontend_prediction = result["Prediction"]  # Extract only the value
        st.write(f"Prediction is {frontend_prediction}.")
    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://kjdeka-test-backend.hf.space/v1/dijakbnbatch", files={"file": file})    # enter user name and backend 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")