Spaces:
Sleeping
Sleeping
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() |