Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,17 +1,72 @@
|
|
| 1 |
-
|
|
|
|
| 2 |
import pandas as pd
|
|
|
|
| 3 |
import numpy as np
|
| 4 |
|
| 5 |
-
|
| 6 |
def full_function(xml_file):
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
-
|
| 14 |
-
return output_text, df
|
| 15 |
|
| 16 |
|
| 17 |
|
|
@@ -25,10 +80,12 @@ with gr.Blocks() as demo:
|
|
| 25 |
# input_question = gr.Text(label="What activity is the Oracle Partner performing?")
|
| 26 |
# additional_info = gr.Text(label="Additional information (optional)")
|
| 27 |
output_text = gr.Text(label="R")
|
| 28 |
-
|
| 29 |
|
| 30 |
|
| 31 |
submit_btn = gr.Button("Run analysis on XML file")
|
| 32 |
|
| 33 |
|
| 34 |
-
gr.Interface(fn=full_function, inputs=xml_file, outputs=
|
|
|
|
|
|
|
|
|
| 1 |
+
from sepa import parser
|
| 2 |
+
import re
|
| 3 |
import pandas as pd
|
| 4 |
+
import gradio as gr
|
| 5 |
import numpy as np
|
| 6 |
|
|
|
|
| 7 |
def full_function(xml_file):
|
| 8 |
|
| 9 |
+
# Utility function to remove additional namespaces from the XML
|
| 10 |
+
def strip_namespace(xml):
|
| 11 |
+
return re.sub(' xmlns="[^"]+"', '', xml, count=1)
|
| 12 |
+
|
| 13 |
+
# Read file
|
| 14 |
+
with open(xml_file, 'r') as f:
|
| 15 |
+
input_data = f.read()
|
| 16 |
+
|
| 17 |
+
# Parse the bank statement XML to dictionary
|
| 18 |
+
camt_dict = parser.parse_string(parser.bank_to_customer_statement, bytes(strip_namespace(input_data), 'utf8'))
|
| 19 |
+
|
| 20 |
+
statements = pd.DataFrame.from_dict(camt_dict['statements'])
|
| 21 |
+
all_entries = []
|
| 22 |
+
for i,_ in statements.iterrows():
|
| 23 |
+
if 'entries' in camt_dict['statements'][i]:
|
| 24 |
+
|
| 25 |
+
#create empty df
|
| 26 |
+
df = pd.DataFrame()
|
| 27 |
+
dd = pd.DataFrame.from_records(camt_dict['statements'][i]['entries'])
|
| 28 |
+
|
| 29 |
+
df['reference'] = dd['reference']
|
| 30 |
+
df['credit_debit_indicator'] = dd['credit_debit_indicator']
|
| 31 |
+
df['status'] = dd['status']
|
| 32 |
+
df['account_servicer_reference'] = dd['account_servicer_reference']
|
| 33 |
+
|
| 34 |
+
iban = camt_dict['statements'][i]['account']['id']['iban']
|
| 35 |
+
name = camt_dict['statements'][i]['account']['name']
|
| 36 |
+
df['iban'] = iban
|
| 37 |
+
df['name'] = name
|
| 38 |
+
df['currency'] = dd['amount'].str['currency']
|
| 39 |
+
df['amount'] = dd['amount'].str['_value']
|
| 40 |
+
|
| 41 |
+
df['value_date'] = dd['value_date'].str['date']
|
| 42 |
+
df['value_date'] = pd.to_datetime(df['value_date']).dt.strftime('%Y-%m-%d')
|
| 43 |
+
df['booking_date'] = dd['booking_date'].str['date']
|
| 44 |
+
df['booking_date'] = pd.to_datetime(df['booking_date']).dt.strftime('%Y-%m-%d')
|
| 45 |
+
|
| 46 |
+
#bank transaction code
|
| 47 |
+
df['proprietary_code'] = dd['bank_transaction_code'].str['proprietary'].str['code']
|
| 48 |
+
df['proprietary_issuer'] = dd['bank_transaction_code'].str['proprietary'].str['issuer']
|
| 49 |
+
|
| 50 |
+
df['domain_code'] = dd['bank_transaction_code'].str['domain'].str['code']
|
| 51 |
+
df['family_code'] = dd['bank_transaction_code'].str['domain'].str['family'].str['code']
|
| 52 |
+
df['sub_family_code'] = dd['bank_transaction_code'].str['domain'].str['family'].str['sub_family_code']
|
| 53 |
+
|
| 54 |
+
#transaction details
|
| 55 |
+
df['debtor_name'] = dd['entry_details'].str[0].str['transaction_details'].str[0].str['related_parties'].str['debtor'].str['name']
|
| 56 |
+
df['debtor_iban'] = dd['entry_details'].str[0].str['transaction_details'].str[0].str['related_parties'].str['debtor_account'].str['id'].str['iban']
|
| 57 |
+
|
| 58 |
+
df['account_servicer_reference'] = dd['entry_details'].str[0].str['transaction_details'].str[0].str['refs'].str['account_servicer_reference']
|
| 59 |
+
df['end_to_end_id'] = dd['entry_details'].str[0].str['transaction_details'].str[0].str['refs'].str['end_to_end_id']
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
all_entries.append(df)
|
| 63 |
+
|
| 64 |
+
df_entries = pd.concat(all_entries)
|
| 65 |
+
df_entries.head()
|
| 66 |
+
|
| 67 |
+
return df_entries
|
| 68 |
+
|
| 69 |
|
|
|
|
|
|
|
| 70 |
|
| 71 |
|
| 72 |
|
|
|
|
| 80 |
# input_question = gr.Text(label="What activity is the Oracle Partner performing?")
|
| 81 |
# additional_info = gr.Text(label="Additional information (optional)")
|
| 82 |
output_text = gr.Text(label="R")
|
| 83 |
+
df_entries = gr.DataFrame(label="Output table")
|
| 84 |
|
| 85 |
|
| 86 |
submit_btn = gr.Button("Run analysis on XML file")
|
| 87 |
|
| 88 |
|
| 89 |
+
gr.Interface(fn=full_function, inputs=xml_file, outputs=df_entries, title=desc).launch(share=True)
|
| 90 |
+
|
| 91 |
+
|