File size: 1,581 Bytes
dab9ea3
 
 
 
 
 
 
 
9813569
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dab9ea3
9813569
 
dab9ea3
9813569
dab9ea3
 
9813569
 
 
 
 
 
dab9ea3
9813569
 
dab9ea3
 
 
 
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
import gradio as gr
import pandas as pd
from extract import extract_upi_transactions
from clean import clean_upi_data
from analysis import analyze_spending_pattern, get_financial_advice
from visualize import plot_spending_by_category

def process_pdf(file):
    """
    Process the uploaded PDF UPI transaction statement.
    Extracts, cleans, analyzes, and visualizes spending data.
    """
    try:
        # βœ… Step 1: Extract transactions
        df = extract_upi_transactions(file.name)

        if df is None or df.empty:
            return "Error: No transactions found in the uploaded PDF.", "", ""

        # βœ… Step 2: Clean data
        df = clean_upi_data(df)

        # βœ… Step 3: Perform financial analysis
        analysis = analyze_spending_pattern(df)

        # βœ… Step 4: Generate financial advice
        advice = get_financial_advice(df)

        # βœ… Step 5: Generate spending visualization
        plot_spending_by_category(df)

        return df, analysis, advice
    
    except Exception as e:
        return f"Error: {str(e)}", "", ""

# βœ… Gradio UI
interface = gr.Interface(
    fn=process_pdf,
    inputs=gr.File(label="Upload UPI PDF Statement"),
    outputs=[
        gr.Dataframe(label="Processed Transaction Data"),
        gr.Textbox(label="Spending Analysis"),
        gr.Textbox(label="Financial Advice"),
    ],
    title="UPI Financial Analyzer",
    description="Upload your UPI transaction statement to get insights, trends, and personalized recommendations.",
    theme="compact",
)

if __name__ == "__main__":
    interface.launch()