Spaces:
Sleeping
Sleeping
File size: 3,416 Bytes
25928ec |
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 |
import gradio as gr
import pandas as pd
# Initialize a dictionary to store account information
accounts = {
"12345": {"name": "John Doe", "balance": 1000.0},
"67890": {"name": "Jane Doe", "balance": 500.0}
}
# Function to create a new account
def create_account(account_number, name, initial_balance):
if account_number in accounts:
return "Account number already exists."
else:
accounts[account_number] = {"name": name, "balance": initial_balance}
return "Account created successfully."
# Function to deposit money into an account
def deposit(account_number, amount):
if account_number in accounts:
accounts[account_number]["balance"] += amount
return f"Deposit successful. New balance: {accounts[account_number]['balance']}"
else:
return "Account number not found."
# Function to withdraw money from an account
def withdraw(account_number, amount):
if account_number in accounts:
if accounts[account_number]["balance"] >= amount:
accounts[account_number]["balance"] -= amount
return f"Withdrawal successful. New balance: {accounts[account_number]['balance']}"
else:
return "Insufficient balance."
else:
return "Account number not found."
# Function to check account balance
def check_balance(account_number):
if account_number in accounts:
return f"Account balance: {accounts[account_number]['balance']}"
else:
return "Account number not found."
# Gradio interface
demo = gr.Blocks()
with demo:
gr.Markdown("# Simple Banking System")
# Create account tab
with gr.Tab("Create Account"):
account_number = gr.Textbox(label="Account Number")
name = gr.Textbox(label="Name")
initial_balance = gr.Number(label="Initial Balance")
create_account_button = gr.Button("Create Account")
create_account_output = gr.Textbox(label="Output")
create_account_button.click(
create_account,
inputs=[account_number, name, initial_balance],
outputs=create_account_output
)
# Deposit tab
with gr.Tab("Deposit"):
account_number_deposit = gr.Textbox(label="Account Number")
amount_deposit = gr.Number(label="Amount")
deposit_button = gr.Button("Deposit")
deposit_output = gr.Textbox(label="Output")
deposit_button.click(
deposit,
inputs=[account_number_deposit, amount_deposit],
outputs=deposit_output
)
# Withdraw tab
with gr.Tab("Withdraw"):
account_number_withdraw = gr.Textbox(label="Account Number")
amount_withdraw = gr.Number(label="Amount")
withdraw_button = gr.Button("Withdraw")
withdraw_output = gr.Textbox(label="Output")
withdraw_button.click(
withdraw,
inputs=[account_number_withdraw, amount_withdraw],
outputs=withdraw_output
)
# Check balance tab
with gr.Tab("Check Balance"):
account_number_balance = gr.Textbox(label="Account Number")
check_balance_button = gr.Button("Check Balance")
balance_output = gr.Textbox(label="Output")
check_balance_button.click(
check_balance,
inputs=[account_number_balance],
outputs=balance_output
)
# Launch the Gradio app
demo.launch()
|