aspirebunny/bank_statement
0
1import streamlit as st2import pandas as pd3import pdfplumber4import io5 6st.set_page_config(page_title="Bank PDF to Excel Converter", layout="centered")7 8st.title("🏦 Bank PDF to Excel Converter")9st.write("Upload your **bank statement PDF**, and I’ll extract useful transaction data for you.")10 11uploaded_file = st.file_uploader("Upload Bank Statement (PDF)", type=["pdf"])12 13if uploaded_file:14 with pdfplumber.open(uploaded_file) as pdf:15 text = ""16 for page in pdf.pages:17 text += page.extract_text() + "\n"18 19 # Example: Extract dummy structured data from PDF text (you can enhance later)20 rows = []21 for line in text.split("\n"):22 parts = line.split()23 if len(parts) >= 4:24 # Try to detect date-like text25 if any(char.isdigit() for char in parts[0]):26 date = parts[0]27 particulars = " ".join(parts[1:-3])28 debit = parts[-3] if parts[-3].replace('.', '', 1).isdigit() else ""29 credit = parts[-2] if parts[-2].replace('.', '', 1).isdigit() else ""30 balance = parts[-1] if parts[-1].replace('.', '', 1).isdigit() else ""31 rows.append([date, particulars, debit, credit, balance])32 33 df = pd.DataFrame(rows, columns=["Date", "Particular", "Debit", "Credit", "Balance"])34 35 # Format date properly if possible36 df["Date"] = pd.to_datetime(df["Date"], errors='coerce').dt.strftime("%d/%m/%Y")37 38 st.dataframe(df)39 40 # Download Excel41 output = io.BytesIO()42 with pd.ExcelWriter(output, engine="xlsxwriter") as writer:43 df.to_excel(writer, index=False, sheet_name="Statement")44 st.download_button("📥 Download Excel File", data=output.getvalue(), file_name="statement.xlsx")45 46else:47 st.info("Please upload a bank PDF to continue.")48 