Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -6,20 +6,46 @@ from analysis import analyze_spending_pattern, get_financial_advice
|
|
6 |
from visualize import plot_spending_by_category
|
7 |
|
8 |
def process_pdf(file):
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
-
|
|
|
16 |
|
|
|
17 |
interface = gr.Interface(
|
18 |
fn=process_pdf,
|
19 |
-
inputs=gr.File(),
|
20 |
-
outputs=[
|
|
|
|
|
|
|
|
|
21 |
title="UPI Financial Analyzer",
|
22 |
-
description="Upload your UPI transaction statement to get insights and recommendations."
|
|
|
23 |
)
|
24 |
|
25 |
if __name__ == "__main__":
|
|
|
6 |
from visualize import plot_spending_by_category
|
7 |
|
8 |
def process_pdf(file):
|
9 |
+
"""
|
10 |
+
Process the uploaded PDF UPI transaction statement.
|
11 |
+
Extracts, cleans, analyzes, and visualizes spending data.
|
12 |
+
"""
|
13 |
+
try:
|
14 |
+
# β
Step 1: Extract transactions
|
15 |
+
df = extract_upi_transactions(file.name)
|
16 |
+
|
17 |
+
if df is None or df.empty:
|
18 |
+
return "Error: No transactions found in the uploaded PDF.", "", ""
|
19 |
+
|
20 |
+
# β
Step 2: Clean data
|
21 |
+
df = clean_upi_data(df)
|
22 |
+
|
23 |
+
# β
Step 3: Perform financial analysis
|
24 |
+
analysis = analyze_spending_pattern(df)
|
25 |
+
|
26 |
+
# β
Step 4: Generate financial advice
|
27 |
+
advice = get_financial_advice(df)
|
28 |
+
|
29 |
+
# β
Step 5: Generate spending visualization
|
30 |
+
plot_spending_by_category(df)
|
31 |
+
|
32 |
+
return df, analysis, advice
|
33 |
|
34 |
+
except Exception as e:
|
35 |
+
return f"Error: {str(e)}", "", ""
|
36 |
|
37 |
+
# β
Gradio UI
|
38 |
interface = gr.Interface(
|
39 |
fn=process_pdf,
|
40 |
+
inputs=gr.File(label="Upload UPI PDF Statement"),
|
41 |
+
outputs=[
|
42 |
+
gr.Dataframe(label="Processed Transaction Data"),
|
43 |
+
gr.Textbox(label="Spending Analysis"),
|
44 |
+
gr.Textbox(label="Financial Advice"),
|
45 |
+
],
|
46 |
title="UPI Financial Analyzer",
|
47 |
+
description="Upload your UPI transaction statement to get insights, trends, and personalized recommendations.",
|
48 |
+
theme="compact",
|
49 |
)
|
50 |
|
51 |
if __name__ == "__main__":
|