test-frontend / app.py
kjdeka's picture
Upload folder using huggingface_hub
17c1521 verified
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")