Ujeshhh commited on
Commit
9813569
Β·
verified Β·
1 Parent(s): c75e97c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -9
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
- df = extract_upi_transactions(file.name)
10
- df = clean_upi_data(df)
11
- analysis = analyze_spending_pattern(df)
12
- advice = get_financial_advice(df)
13
- plot_spending_by_category(df)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
 
15
- return df, analysis, advice
 
16
 
 
17
  interface = gr.Interface(
18
  fn=process_pdf,
19
- inputs=gr.File(),
20
- outputs=[gr.Dataframe(), "text", "text"],
 
 
 
 
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__":