Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,6 +3,40 @@ import pandas as pd
|
|
| 3 |
import matplotlib.pyplot as plt
|
| 4 |
import seaborn as sns
|
| 5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
# Initialize an empty DataFrame to hold expenses data
|
| 7 |
columns = ['Date', 'Category', 'Description', 'Amount']
|
| 8 |
if 'expenses_df' not in st.session_state:
|
|
@@ -69,7 +103,8 @@ if user_input:
|
|
| 69 |
st.session_state['messages'].append({"role": "assistant", "content": response})
|
| 70 |
|
| 71 |
# Expense Addition Flow
|
| 72 |
-
|
|
|
|
| 73 |
date = st.date_input("Enter Expense Date")
|
| 74 |
category = st.selectbox("Category", ['Food', 'Transport', 'Entertainment', 'Other'])
|
| 75 |
description = st.text_input("Description")
|
|
|
|
| 3 |
import matplotlib.pyplot as plt
|
| 4 |
import seaborn as sns
|
| 5 |
|
| 6 |
+
# Initialize an empty DataFrame to hold expenses data
|
| 7 |
+
columns = ['Date', 'Category', 'Description', 'Amount']
|
| 8 |
+
if 'expenses_df' not in st.session_state:
|
| 9 |
+
st.session_state['expenses_df'] = pd.DataFrame(columns=columns)
|
| 10 |
+
|
| 11 |
+
# Initialize a list for storing messages between user and bot
|
| 12 |
+
if 'messages' not in st.session_state:
|
| 13 |
+
st.session_state['messages'] = []
|
| 14 |
+
|
| 15 |
+
# Function to add an expense
|
| 16 |
+
def add_expense(date, category, description, amount):
|
| 17 |
+
new_expense = pd.DataFrame([[date, category, description, amount]], columns=st.session_state['expenses_df'].columns)
|
| 18 |
+
st.session_state['expenses_df'] = pd.concat([st.session_state['expenses_df'], new_expense], ignore_index=True)
|
| 19 |
+
|
| 20 |
+
# Function to generate response for the chatbot
|
| 21 |
+
def chatbot_response(user_input):
|
| 22 |
+
# If the user wants to add an expense, we can extract the details from the input
|
| 23 |
+
if "add" in user_input.lower() and "expense" in user_input.lower():
|
| 24 |
+
# Ask the user for details about the expense
|
| 25 |
+
st.session_state['messages'].append({"role": "assistant", "content": "Please enter the date of the expense."})
|
| 26 |
+
return "Please enter the date of the expense."
|
| 27 |
+
|
| 28 |
+
elif "view" in user_input.lower():
|
| 29 |
+
st.session_state['messages'].append({"role": "assistant", "content": str(st.session_state['expenses_df'])})
|
| 30 |
+
return "Here are all your expenses:\n" + str(st.session_state['expenses_df'])
|
| 31 |
+
|
| 32 |
+
elif "summary" in user_input.lower():
|
| 33 |
+
category_summary = st.session_state['expenses_df'].groupby('Category')['Amount'].sum().reset_index()
|
| 34 |
+
st.session_state['messages'].append({"role": "assistant", "content": str(category_summary)})
|
| 35 |
+
return "Here is the expense suimport streamlit as st
|
| 36 |
+
import pandas as pd
|
| 37 |
+
import matplotlib.pyplot as plt
|
| 38 |
+
import seaborn as sns
|
| 39 |
+
|
| 40 |
# Initialize an empty DataFrame to hold expenses data
|
| 41 |
columns = ['Date', 'Category', 'Description', 'Amount']
|
| 42 |
if 'expenses_df' not in st.session_state:
|
|
|
|
| 103 |
st.session_state['messages'].append({"role": "assistant", "content": response})
|
| 104 |
|
| 105 |
# Expense Addition Flow
|
| 106 |
+
# Ensure there is at least one message and check for the assistant's message asking for date input
|
| 107 |
+
if st.session_state['messages'] and "Please enter the date of the expense." in st.session_state['messages'][-1].get("content", ""):
|
| 108 |
date = st.date_input("Enter Expense Date")
|
| 109 |
category = st.selectbox("Category", ['Food', 'Transport', 'Entertainment', 'Other'])
|
| 110 |
description = st.text_input("Description")
|