engralimalik commited on
Commit
e6dd97e
·
verified ·
1 Parent(s): 0dec30d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -5
app.py CHANGED
@@ -2,9 +2,40 @@ import pandas as pd
2
  import plotly.express as px
3
  import streamlit as st
4
  from transformers import pipeline
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
  # File upload
7
  uploaded_file = st.file_uploader("Upload your expense CSV file", type=["csv"])
 
8
  if uploaded_file:
9
  df = pd.read_csv(uploaded_file)
10
 
@@ -17,9 +48,7 @@ if uploaded_file:
17
 
18
  # Function to categorize
19
  def categorize_expense(description):
20
- # Check raw output from the model for debugging
21
  result = classifier(description, candidate_labels=categories)
22
- st.write(f"Raw classification result for '{description}': {result}") # Debugging line
23
  return result['labels'][0] # Most probable category
24
 
25
  # Apply categorization
@@ -69,11 +98,11 @@ if uploaded_file:
69
  fig2 = px.line(monthly_expenses, x=monthly_expenses.index, y=monthly_expenses.values, title="Monthly Expenses", labels={"x": "Month", "y": "Amount ($)"})
70
  st.plotly_chart(fig2)
71
 
72
- # 3. Monthly Spending vs Budget (Bar Chart with Plotly)
73
  monthly_expenses_df = pd.DataFrame({
74
  'Actual': monthly_expenses,
75
  'Budget': [sum(budgets.values())] * len(monthly_expenses) # Same budget for simplicity
76
  })
77
 
78
- fig3 = px.bar(monthly_expenses_df, x=monthly_expenses_df.index, y=["Actual", "Budget"], title="Monthly Spending vs Budget", labels={"x": "Month", "y": "Amount ($)"})
79
- st.plotly_chart(fig3)
 
2
  import plotly.express as px
3
  import streamlit as st
4
  from transformers import pipeline
5
+ import base64
6
+
7
+ # Function to add custom background image
8
+ def add_bg_from_url(image_path):
9
+ # Convert image to base64
10
+ with open(image_path, "rb") as image_file:
11
+ encoded_string = base64.b64encode(image_file.read()).decode()
12
+
13
+ # HTML for background image
14
+ st.markdown(
15
+ f"""
16
+ <style>
17
+ .stApp {{
18
+ background-image: url("data:image/png;base64,{encoded_string}");
19
+ background-size: cover;
20
+ background-position: center center;
21
+ background-repeat: no-repeat;
22
+ }}
23
+ </style>
24
+ """,
25
+ unsafe_allow_html=True
26
+ )
27
+
28
+ # Add background image (replace with your image path)
29
+ add_bg_from_url('path_to_your_image.jpg') # Replace with your image path
30
+
31
+ # Title and header styling
32
+ st.markdown("""
33
+ <h1 style="color: #00f7b7; font-family: 'Arial', sans-serif; text-align: center;">Smart Expense Tracker</h1>
34
+ """, unsafe_allow_html=True)
35
 
36
  # File upload
37
  uploaded_file = st.file_uploader("Upload your expense CSV file", type=["csv"])
38
+
39
  if uploaded_file:
40
  df = pd.read_csv(uploaded_file)
41
 
 
48
 
49
  # Function to categorize
50
  def categorize_expense(description):
 
51
  result = classifier(description, candidate_labels=categories)
 
52
  return result['labels'][0] # Most probable category
53
 
54
  # Apply categorization
 
98
  fig2 = px.line(monthly_expenses, x=monthly_expenses.index, y=monthly_expenses.values, title="Monthly Expenses", labels={"x": "Month", "y": "Amount ($)"})
99
  st.plotly_chart(fig2)
100
 
101
+ # 3. Monthly Spending vs Budget (Bar Chart)
102
  monthly_expenses_df = pd.DataFrame({
103
  'Actual': monthly_expenses,
104
  'Budget': [sum(budgets.values())] * len(monthly_expenses) # Same budget for simplicity
105
  })
106
 
107
+ fig3 = monthly_expenses_df.plot(kind='bar', figsize=(10, 6))
108
+ st.pyplot(fig3)