pm6six commited on
Commit
23c1fce
·
verified ·
1 Parent(s): 70c393b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -9
app.py CHANGED
@@ -1,14 +1,15 @@
1
- import gradio as gr
2
  import pdfplumber
3
  import pandas as pd
4
 
5
  # Function to process PDF and classify transactions
6
- def process_pdf(file_path):
7
- if file_path is None:
8
- return "No file uploaded."
 
9
 
10
  # Extract text from the uploaded PDF
11
- with pdfplumber.open(file_path) as pdf:
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 # Display the table
39
 
40
- # Fix: Use "filepath" instead of "file"
41
- app = gr.Interface(fn=process_pdf, inputs=gr.File(type="filepath"), outputs="dataframe", title="Bank Statement Classifier")
42
- app.launch()
 
 
 
 
 
 
 
 
 
 
 
 
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