Update app.py
Browse files
app.py
CHANGED
@@ -1,14 +1,15 @@
|
|
1 |
-
import
|
2 |
import pdfplumber
|
3 |
import pandas as pd
|
4 |
|
5 |
# Function to process PDF and classify transactions
|
6 |
-
def process_pdf(
|
7 |
-
if
|
8 |
-
|
|
|
9 |
|
10 |
# Extract text from the uploaded PDF
|
11 |
-
with pdfplumber.open(
|
12 |
text = "\n".join([page.extract_text() for page in pdf.pages if page.extract_text()])
|
13 |
|
14 |
# Extract transactions (Modify based on statement format)
|
@@ -35,9 +36,21 @@ def process_pdf(file_path):
|
|
35 |
# Apply classification
|
36 |
df["Category"] = df["Description"].apply(classify_transaction)
|
37 |
|
38 |
-
return df #
|
39 |
|
40 |
-
#
|
41 |
-
|
42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
|
|
|
1 |
+
import streamlit as st
|
2 |
import pdfplumber
|
3 |
import pandas as pd
|
4 |
|
5 |
# Function to process PDF and classify transactions
|
6 |
+
def process_pdf(file):
|
7 |
+
if file is None:
|
8 |
+
st.error("No file uploaded.")
|
9 |
+
return None
|
10 |
|
11 |
# Extract text from the uploaded PDF
|
12 |
+
with pdfplumber.open(file) as pdf:
|
13 |
text = "\n".join([page.extract_text() for page in pdf.pages if page.extract_text()])
|
14 |
|
15 |
# Extract transactions (Modify based on statement format)
|
|
|
36 |
# Apply classification
|
37 |
df["Category"] = df["Description"].apply(classify_transaction)
|
38 |
|
39 |
+
return df # Return DataFrame
|
40 |
|
41 |
+
# Streamlit UI
|
42 |
+
st.title("📄 Credit Card Statement Classifier")
|
43 |
+
st.write("Upload a PDF bank/credit card statement to categorize transactions.")
|
44 |
+
|
45 |
+
uploaded_file = st.file_uploader("Upload PDF", type=["pdf"])
|
46 |
+
|
47 |
+
if uploaded_file is not None:
|
48 |
+
st.success("File uploaded successfully!")
|
49 |
+
|
50 |
+
# Process and display transactions
|
51 |
+
df_result = process_pdf(uploaded_file)
|
52 |
+
|
53 |
+
if df_result is not None:
|
54 |
+
st.write("### Classified Transactions:")
|
55 |
+
st.dataframe(df_result) # Display table
|
56 |
|