import streamlit as st import pandas as pd from src.services import BankStatementService from src.utils import model_manager import asyncio st.set_page_config(page_title="Bank Statement Analyzer", layout="wide") st.title("📄 Bank Statement Analyzer") async def preload_models(): await model_manager.ensure_models_loaded() async def process_file(uploaded_file): async with BankStatementService() as service: return await service.process_bank_statement(uploaded_file) # Pre-load models only once if 'models_loaded' not in st.session_state: st.session_state.models_loaded = False asyncio.run(preload_models()) st.session_state.models_loaded = True uploaded_file = st.file_uploader("Upload Bank Statement PDF", type=["pdf"]) if uploaded_file: st.info("📥 Processing uploaded file...") with st.spinner("Extracting data..."): result = asyncio.run(process_file(uploaded_file)) if result: # --- Account Summary --- account_df = pd.DataFrame(result.account_summary.items(), columns=["Account Summary", "Data"]) st.dataframe(account_df, use_container_width=True, hide_index=True) # --- Tables Section --- st.subheader("📊 Extracted Tables") for name, df in result.transaction_tables.items(): if df.empty: continue st.markdown(f"### {name.capitalize()} Table") st.dataframe(df, use_container_width=True, hide_index=True) else: st.error("⚠️ Unable to parse the statement correctly.") else: st.warning("📤 Please upload a PDF file to begin.")