Azmathussainthebo's picture
Update app.py
b94e0b0 verified
import streamlit as st
from dotenv import load_dotenv
import os
import pandas as pd
from transformers import pipeline
# Load environment variables from the .env file
load_dotenv()
HUGGINGFACE_API_KEY = os.getenv("HUGGINGFACE_API_KEY")
st.title("Smart Budget Planner")
# Input for monthly income
income = st.number_input("Enter your monthly income:", min_value=0.0, step=0.01)
st.header("Add Your Expenses")
# Create a form to add expenses
with st.form(key='expense_form'):
expense_name = st.text_input("Expense Name")
expense_amount = st.number_input("Expense Amount", min_value=0.0, step=0.01)
add_expense = st.form_submit_button("Add Expense")
# Initialize expenses in session_state if not present
if "expenses" not in st.session_state:
st.session_state.expenses = []
# When the form is submitted, add the expense
if add_expense and expense_name and expense_amount:
st.session_state.expenses.append({"name": expense_name, "amount": expense_amount})
st.success(f"Added expense: {expense_name} - {expense_amount}")
# Display the list of expenses
if st.session_state.expenses:
st.subheader("Your Expenses")
df = pd.DataFrame(st.session_state.expenses)
st.table(df)
# Calculate and display budget summary
total_expenses = sum(item["amount"] for item in st.session_state.expenses)
remaining_budget = income - total_expenses
st.subheader("Budget Summary")
st.write(f"**Total Expenses:** {total_expenses:.2f}")
st.write(f"**Remaining Budget:** {remaining_budget:.2f}")
else:
st.info("No expenses added yet.")
# Integration with a Hugging Face model for sentiment analysis
st.header("Budget Sentiment Analysis")
if st.button("Analyze Budget"):
# Prepare a summary text for analysis
summary_text = f"My monthly income is {income} and my total expenses are {total_expenses if st.session_state.expenses else 0}."
st.write("Analyzing the following text:")
st.write(summary_text)
# Use a sentiment-analysis pipeline (model: distilbert-base-uncased-finetuned-sst-2-english)
classifier = pipeline("sentiment-analysis", model="distilbert-base-uncased-finetuned-sst-2-english")
result = classifier(summary_text)
st.write("**Sentiment Analysis Result:**")
st.write(result)