-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
140 lines (106 loc) · 3.58 KB
/
app.py
File metadata and controls
140 lines (106 loc) · 3.58 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import streamlit as st
import builtins
from main import Bank
# Initialize
user = Bank()
st.set_page_config(page_title="Banking System", layout="centered")
st.title("💳 Banking System")
# Sidebar menu
menu = st.sidebar.radio("Select Operation", [
"Create Account",
"Deposit Money",
"Withdraw Money",
"Show Details",
"Update Details",
"Delete Account",
"Transfer Money"
])
# ---------------- INPUT OVERRIDE FUNCTION ----------------
def run_with_inputs(func, inputs_list):
original_input = builtins.input
inputs = iter(inputs_list)
builtins.input = lambda _: next(inputs)
try:
func()
st.success("Operation executed successfully ✅")
except Exception as e:
st.error(f"Error: {e}")
finally:
builtins.input = original_input
# ---------------- CREATE ACCOUNT ----------------
if menu == "Create Account":
st.subheader("Create New Account")
name = st.text_input("Full Name")
age = st.number_input("Age", min_value=1)
email = st.text_input("Email")
pin = st.text_input("4-digit PIN")
if st.button("Create Account"):
if name and email and pin:
run_with_inputs(user.createaccount, [
name, str(age), email, pin
])
else:
st.warning("Please fill all fields")
# ---------------- DEPOSIT ----------------
elif menu == "Deposit Money":
st.subheader("Deposit Money")
acc = st.text_input("Account Number")
pin = st.text_input("PIN")
amount = st.number_input("Amount", min_value=1)
if st.button("Deposit"):
run_with_inputs(user.depositmoney, [
acc, pin, str(amount)
])
# ---------------- WITHDRAW ----------------
elif menu == "Withdraw Money":
st.subheader("Withdraw Money")
acc = st.text_input("Account Number")
pin = st.text_input("PIN")
amount = st.number_input("Amount", min_value=1)
if st.button("Withdraw"):
run_with_inputs(user.withdrawmoney, [
acc, pin, str(amount)
])
# ---------------- SHOW DETAILS ----------------
elif menu == "Show Details":
st.subheader("Account Details")
acc = st.text_input("Account Number")
pin = st.text_input("PIN")
if st.button("Show Details"):
run_with_inputs(user.showdetails, [
acc, pin
])
st.info("ℹ️ Output is printed in terminal")
# ---------------- UPDATE ----------------
elif menu == "Update Details":
st.subheader("Update Account")
acc = st.text_input("Account Number")
pin = st.text_input("PIN")
name = st.text_input("New Name (optional)")
email = st.text_input("New Email (optional)")
new_pin = st.text_input("New PIN (optional)")
if st.button("Update"):
run_with_inputs(user.updatedetails, [
acc, pin, name, email, new_pin
])
# ---------------- DELETE ----------------
elif menu == "Delete Account":
st.subheader("Delete Account")
acc = st.text_input("Account Number")
pin = st.text_input("PIN")
confirm = st.selectbox("Confirm Delete", ["n", "Y"])
if st.button("Delete"):
run_with_inputs(user.deleteaccount, [
acc, pin, confirm
])
# ---------------- TRANSFER ----------------
elif menu == "Transfer Money":
st.subheader("Transfer Money")
sender = st.text_input("Sender Account")
pin = st.text_input("Sender PIN")
receiver = st.text_input("Receiver Account")
amount = st.number_input("Amount", min_value=1)
if st.button("Transfer"):
run_with_inputs(user.transfermoney, [
sender, pin, receiver, str(amount)
])