import streamlit as st import joblib model = joblib.load("fraud_model.pkl") pages = ["Test Case 1", "Test Case 2"] st.sidebar.title("Navigation") selected_page = st.sidebar.radio("Go to", pages) non_fraudulent_data = { "Name": "Jamshidov Ozod", "Location": "Tashkent", "Time since last transaction": "3 seconds", "Amount spent": "100,000 UZS", "Device used": "Xiaomi Phone", "Transaction type": "ATM withdrawal", "Frequency of transactions today": "5", "Distance from home": "10 km", "Past avg transaction amount": "50,000 UZS", "Merchant category": "Retail store (Grocery)", "User's spending limit": "2,000,000 UZS", "User's current balance": "1,500,000 UZS", "User's age": "35 years old" } fraudulent_data = { "Name": "Rustam Karimov", "Location": "Samarkand", "Time since last transaction": "20 seconds", "Amount spent": "2,000,000 UZS", "Device used": "iPhone 13", "Transaction type": "Online purchase", "Frequency of transactions today": "15", "Distance from home": "200 km", "Past avg transaction amount": "100,000 UZS", "Merchant category": "Electronics store (Retail)", "User's spending limit": "5,000,000 UZS", "User's current balance": "100,000 UZS", "User's age": "45 years old", "Risk score": "High" } if selected_page == "Test Case 1": st.subheader("Test Case 1: Non-Fraudulent Transaction") st.write("### Transaction Details") col1, col2 = st.columns(2) with col1: for key, value in list(non_fraudulent_data.items())[:6]: st.write(f"**{key}:** {value}") with col2: for key, value in list(non_fraudulent_data.items())[6:]: st.write(f"**{key}:** {value}") if st.button("Submit Data"): mapped_pca_values = [ -0.986639536, 0.054619774, 0.89218939, 1.238546301, 1.153949202, -0.443156858, 1.158792971, -0.234932879, -0.748284316, 0.19999764, -0.377070284, -0.086545898, 0.217167156, 0.314289834, 1.295545516, -0.818801496, 0.059642158, -0.68956288, 0.684420234, 0.744324727, -0.15608398, -0.590576405, 0.432953111, -0.337631423, -0.272390765, -0.551474596, 0.171669591, 0.012712389, 148.81, 0.3333 ] prediction = model.predict([mapped_pca_values]) st.success(f"Prediction for Jamshidov Ozod: {'Fraud' if prediction[0] == 1 else 'Non-fraud'}") elif selected_page == "Test Case 2": st.subheader("Test Case 2: Fraudulent Transaction") st.write("### Transaction Details") col1, col2 = st.columns(2) with col1: for key, value in list(fraudulent_data.items())[:6]: # First half of the data st.write(f"**{key}:** {value}") with col2: for key, value in list(fraudulent_data.items())[6:]: # Second half of the data st.write(f"**{key}:** {value}") if st.button("Submit Data"): positive_case_values = [ 28726, -29.87636551, 16.43452455, -30.55869682, 6.505861787, -21.6656543, -4.940356329, -20.08139107, 19.58777262, -3.591491047, -7.800598208, 3.947839717, -5.487911486, 1.369940349, -4.829552443, -0.134412095, -5.121162405, -11.11819045, -4.65995587, 0.608930081, 1.724778838, 1.812953975, -2.232251588, -1.412803443, 0.17873107, 2.156041858, -0.209384624, 1.255648901, 0.364530453, 99.99 ] prediction = model.predict([positive_case_values]) st.success(f"Prediction for Rustam Karimov: {'Fraud' if prediction[0] == 1 else 'Non-fraud'}")