gradio-banking / app.py
louiecerv
saved changes
25928ec
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()