Spaces:
Build error
Build error
Download utils.py from jonels1988/OCR-App: direct link, hf CLI and curl.
- Browser
- Download file 1.64 kB
-
https://huggingface.co/spaces/jonels1988/OCR-App/resolve/main/utils.py
- Command line
-
hf download hf://spaces/jonels1988/OCR-App/utils.py
-
curl -L -o utils.py https://huggingface.co/spaces/jonels1988/OCR-App/resolve/main/utils.py
1.64 kB
| import pandas as pd | |
| from models import Transaction | |
| def transactions_to_dataframe(transactions): | |
| """Convert transactions to pandas DataFrame""" | |
| data = [] | |
| for t in transactions: | |
| data.append({ | |
| 'Date': t.date, | |
| 'Description': t.description, | |
| 'Amount': f"${t.amount:.2f}", | |
| 'Type': t.transaction_type, | |
| 'Category': t.category | |
| }) | |
| return pd.DataFrame(data) | |
| def calculate_totals(transactions): | |
| """Calculate total credits and debits""" | |
| total_credits = sum(t.amount for t in transactions if t.transaction_type == 'credit') | |
| total_debits = sum(t.amount for t in transactions if t.transaction_type == 'debit') | |
| net_amount = total_credits - total_debits | |
| return { | |
| 'total_credits': total_credits, | |
| 'total_debits': total_debits, | |
| 'net_amount': net_amount | |
| } | |
| def generate_statement_report(statement_data): | |
| """Generate a text report from statement data""" | |
| report = [] | |
| report.append(f"Bank: {statement_data.get('bank_name', 'Unknown')}") | |
| report.append(f"Account: {statement_data.get('account_number', 'Unknown')}") | |
| report.append("") | |
| transactions = [Transaction(**t) for t in statement_data.get('transactions', [])] | |
| totals = calculate_totals(transactions) | |
| report.append(f"Total Credits: ${totals['total_credits']:.2f}") | |
| report.append(f"Total Debits: ${totals['total_debits']:.2f}") | |
| report.append(f"Net Amount: ${totals['net_amount']:.2f}") | |
| report.append("") | |
| report.append(f"Number of Transactions: {len(transactions)}") | |
| return "\n".join(report) |