Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,66 +1,79 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import subprocess
|
|
|
|
|
|
|
| 3 |
|
| 4 |
-
|
| 5 |
-
def run_setup():
|
| 6 |
result = subprocess.run(
|
| 7 |
-
["
|
| 8 |
capture_output=True,
|
| 9 |
text=True
|
| 10 |
)
|
| 11 |
-
return result.stdout
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
result = subprocess.run(
|
| 23 |
-
[f"./cobol/{binary_name}"],
|
| 24 |
-
input=input_data,
|
| 25 |
-
capture_output=True,
|
| 26 |
-
text=True,
|
| 27 |
-
timeout=10
|
| 28 |
-
)
|
| 29 |
-
else:
|
| 30 |
-
result = subprocess.run(
|
| 31 |
-
[f"./cobol/{binary_name}"],
|
| 32 |
-
capture_output=True,
|
| 33 |
-
text=True,
|
| 34 |
-
timeout=10
|
| 35 |
-
)
|
| 36 |
-
return result.stdout or result.stderr
|
| 37 |
-
except Exception as e:
|
| 38 |
-
return str(e)
|
| 39 |
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
|
|
|
| 44 |
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
|
|
|
| 49 |
|
| 50 |
-
|
| 51 |
-
with
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
acc_output = gr.Textbox(label="Balance Info")
|
| 57 |
-
acc_btn = gr.Button("Check Balance")
|
| 58 |
-
acc_btn.click(fn=get_balance, inputs=acc_input, outputs=acc_output)
|
| 59 |
|
| 60 |
-
with gr.Tab("
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
|
| 66 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import subprocess
|
| 3 |
+
import pandas as pd
|
| 4 |
+
from pathlib import Path
|
| 5 |
|
| 6 |
+
def run_cobol_binary(action, data):
|
|
|
|
| 7 |
result = subprocess.run(
|
| 8 |
+
["./cobol/account", action, data],
|
| 9 |
capture_output=True,
|
| 10 |
text=True
|
| 11 |
)
|
| 12 |
+
return result.stdout or result.stderr
|
| 13 |
|
| 14 |
+
def create_account(number, name, balance):
|
| 15 |
+
input_str = f"{number},{name},{balance}"
|
| 16 |
+
result = subprocess.run(["./cobol/account", "CREATE", input_str], capture_output=True, text=True)
|
| 17 |
+
return "β
Account created"
|
| 18 |
|
| 19 |
+
def create_loan(lid, acc_id, amount, rate, status):
|
| 20 |
+
input_str = f"{lid},{acc_id},{amount},{rate},{status}"
|
| 21 |
+
result = subprocess.run(["./cobol/loan", "CREATE", input_str], capture_output=True, text=True)
|
| 22 |
+
return "β
Loan created"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
+
def export_accounts():
|
| 25 |
+
df = pd.read_csv("data/accounts.csv")
|
| 26 |
+
path = "export_accounts.csv"
|
| 27 |
+
df.to_csv(path, index=False)
|
| 28 |
+
return path
|
| 29 |
|
| 30 |
+
def export_loans():
|
| 31 |
+
df = pd.read_csv("data/loans.csv")
|
| 32 |
+
path = "export_loans.csv"
|
| 33 |
+
df.to_csv(path, index=False)
|
| 34 |
+
return path
|
| 35 |
|
| 36 |
+
def get_log():
|
| 37 |
+
with open("data/transactions.log", "r") as f:
|
| 38 |
+
content = f.read()
|
| 39 |
+
return f"""
|
| 40 |
+
<div class="transaction-log">
|
| 41 |
+
{content.replace('\n', '<br>')}
|
| 42 |
+
</div>
|
| 43 |
+
"""
|
| 44 |
|
| 45 |
+
with gr.Blocks(title="COBOL Bank Demo", css="file=static/style.css") as demo:
|
| 46 |
+
gr.Markdown("# π° COBOL Banking System\nCreate, read, and export accounts and loans")
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
+
with gr.Tab("Accounts"):
|
| 49 |
+
with gr.Row():
|
| 50 |
+
acc_num = gr.Number(label="Account Number")
|
| 51 |
+
acc_name = gr.Textbox(label="Name")
|
| 52 |
+
acc_bal = gr.Number(label="Balance")
|
| 53 |
+
acc_btn = gr.Button("Create Account")
|
| 54 |
+
acc_btn.click(fn=create_account, inputs=[acc_num, acc_name, acc_bal], outputs=[])
|
| 55 |
+
|
| 56 |
+
exp_acc_btn = gr.Button("Export Accounts")
|
| 57 |
+
exp_acc_file = gr.File(label="Download Accounts CSV")
|
| 58 |
+
exp_acc_btn.click(fn=export_accounts, outputs=exp_acc_file)
|
| 59 |
+
|
| 60 |
+
with gr.Tab("Loans"):
|
| 61 |
+
with gr.Row():
|
| 62 |
+
loan_id = gr.Textbox(label="Loan ID")
|
| 63 |
+
loan_acc = gr.Number(label="Account Number")
|
| 64 |
+
loan_amt = gr.Number(label="Amount")
|
| 65 |
+
loan_rate = gr.Number(label="Rate (%)")
|
| 66 |
+
loan_status = gr.Textbox(label="Status")
|
| 67 |
+
loan_btn = gr.Button("Create Loan")
|
| 68 |
+
loan_btn.click(fn=create_loan, inputs=[loan_id, loan_acc, loan_amt, loan_rate, loan_status], outputs=[])
|
| 69 |
+
|
| 70 |
+
exp_loan_btn = gr.Button("Export Loans")
|
| 71 |
+
exp_loan_file = gr.File(label="Download Loans CSV")
|
| 72 |
+
exp_loan_btn.click(fn=export_loans, outputs=exp_loan_file)
|
| 73 |
+
|
| 74 |
+
with gr.Tab("Transaction Log"):
|
| 75 |
+
log_box = gr.HTML(label="Logs", value=get_log)
|
| 76 |
+
refresh_btn = gr.Button("Refresh Log")
|
| 77 |
+
refresh_btn.click(fn=get_log, outputs=log_box)
|
| 78 |
|
| 79 |
demo.launch()
|