Spaces:
Runtime error
Runtime error
File size: 1,621 Bytes
4e71548 02d8e46 4e71548 02d8e46 4e71548 02d8e46 4e71548 02d8e46 4e71548 02d8e46 4e71548 02d8e46 4e71548 02d8e46 4e71548 02d8e46 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
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.") |