puffy310 commited on
Commit
42d73cb
·
verified ·
1 Parent(s): 63d5f31

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -17
app.py CHANGED
@@ -1,15 +1,7 @@
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}"
@@ -34,13 +26,17 @@ def export_loans():
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")
@@ -72,7 +68,7 @@ with gr.Blocks(title="COBOL Bank Demo", css="file=static/style.css") as demo:
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
 
 
1
  import gradio as gr
2
  import subprocess
3
  import pandas as pd
4
+ import os
 
 
 
 
 
 
 
 
5
 
6
  def create_account(number, name, balance):
7
  input_str = f"{number},{name},{balance}"
 
26
  return path
27
 
28
  def get_log():
29
+ try:
30
+ with open("data/transactions.log", "r") as f:
31
+ content = f.read()
32
+ html_content = content.replace('\n', '<br>')
33
+ return f"""
34
+ <div class="transaction-log">
35
+ {html_content}
36
+ </div>
37
+ """
38
+ except Exception as e:
39
+ return f"<div class='transaction-log'>Error reading log: {str(e)}</div>"
40
 
41
  with gr.Blocks(title="COBOL Bank Demo", css="file=static/style.css") as demo:
42
  gr.Markdown("# 💰 COBOL Banking System\nCreate, read, and export accounts and loans")
 
68
  exp_loan_btn.click(fn=export_loans, outputs=exp_loan_file)
69
 
70
  with gr.Tab("Transaction Log"):
71
+ log_box = gr.HTML(label="Logs", value=get_log())
72
  refresh_btn = gr.Button("Refresh Log")
73
  refresh_btn.click(fn=get_log, outputs=log_box)
74