credit / app.py
saifsunny's picture
Update app.py
4ee2b4f verified
import streamlit as st
import pandas as pd
import joblib
st.title('Fraud Detection')
st.write('Please review the attributes below, then hit the Submit button to get your results.')
st.header('Input Attributes')
# Define the sliders with the specified range
time = st.number_input('Time', min_value=0.0, max_value=20000.0, value=472.0, step=1.0)
v3 = st.number_input('V3', min_value=-4.0, max_value=4.0, value=1.088, step=0.001)
v7 = st.number_input('V7', min_value=-4.0, max_value=4.0, value=0.325, step=0.001)
v10 = st.number_input('V10', min_value=-4.0, max_value=4.0, value=-0.838, step=0.001)
v12 = st.number_input('V12', min_value=-4.0, max_value=4.0, value=-0.414, step=0.001)
v14 = st.number_input('V14', min_value=-4.0, max_value=4.0, value=-0.503, step=0.001)
v16 = st.number_input('V16', min_value=-4.0, max_value=4.0, value=-1.692, step=0.001)
v17 = st.number_input('V17', min_value=-4.0, max_value=4.0, value=0.666, step=0.001)
amount = st.number_input('Amount', min_value=1.0, max_value=30000.0, value=529.0, step=0.1)
submit_button = st.button('Submit')
if submit_button:
try:
# Load the model from the file
ensemble_model = joblib.load('updated_ensemble.pkl')
# Create new data with the specified columns
new_data = pd.DataFrame({
'Time': [time],
'V3': [v3],
'V7': [v7],
'V10': [v10],
'V12': [v12],
'V14': [v14],
'V16': [v16],
'V17': [v17],
'Amount': [amount]
})
# Predict using the ensemble model
prediction = ensemble_model.predict(new_data)
st.header('Prediction')
if prediction[0] == 0:
st.title('Not Fraud')
else:
st.title('Fraud')
except Exception as e:
st.error(f"An error occurred: {e}")
st.error("Ensure the model file is in the correct path")