Spaces:
Runtime error
Runtime error
HarshEra commited on
Tool: finance_management_plan was added !!!
Browse files
app.py
CHANGED
|
@@ -9,14 +9,60 @@ from Gradio_UI import GradioUI
|
|
| 9 |
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
@tool
|
| 12 |
-
def
|
| 13 |
-
|
| 14 |
-
|
| 15 |
Args:
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
"""
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 9 |
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
@tool
|
| 12 |
+
def finance_management_plan(budget: float, habits: str, goal: str, period: str) -> str:
|
| 13 |
+
"""A tool that gives a plan to optimize personal budget and spending based on habits and financial goals.
|
| 14 |
+
|
| 15 |
Args:
|
| 16 |
+
budget (float): A float representing the current budget (e.g., '100.000').
|
| 17 |
+
habits (str): The expense habits each day of the week (e.g., 'Monday: $50, Tuesday: $30, ...').
|
| 18 |
+
goal (str): Financial goals to achieve (e.g., 'Save $500 for a vacation').
|
| 19 |
+
period (str): The time period in which the user wants a plan to achieve the goal (e.g., 'week', 'month').
|
| 20 |
+
|
| 21 |
+
Returns:
|
| 22 |
+
str: A personalized plan to optimize the budget and achieve the financial goal.
|
| 23 |
"""
|
| 24 |
+
# Parse habits into a dictionary
|
| 25 |
+
habits_dict = {}
|
| 26 |
+
for day in habits.split(','):
|
| 27 |
+
day, amount = day.strip().split(':')
|
| 28 |
+
habits_dict[day.strip()] = float(amount.strip().replace('$', ''))
|
| 29 |
+
|
| 30 |
+
# Calculate total weekly spending based on habits
|
| 31 |
+
total_weekly_spending = sum(habits_dict.values())
|
| 32 |
+
|
| 33 |
+
# Determine the total budget for the specified period
|
| 34 |
+
if period.lower() == 'week':
|
| 35 |
+
total_budget = budget
|
| 36 |
+
elif period.lower() == 'month':
|
| 37 |
+
total_budget = budget * 4 # Assuming 4 weeks in a month
|
| 38 |
+
else:
|
| 39 |
+
return "Invalid period. Please specify 'week' or 'month'."
|
| 40 |
+
|
| 41 |
+
# Calculate savings needed to achieve the goal
|
| 42 |
+
goal_amount = float(''.join(filter(str.isdigit, goal))) # Extract numeric value from goal string
|
| 43 |
+
savings_needed = goal_amount - (total_budget - total_weekly_spending)
|
| 44 |
+
|
| 45 |
+
# Generate a plan
|
| 46 |
+
if savings_needed <= 0:
|
| 47 |
+
return f"Your current budget and spending habits already allow you to achieve your goal of {goal} within the {period}."
|
| 48 |
+
else:
|
| 49 |
+
# Suggest reducing daily expenses
|
| 50 |
+
daily_savings = savings_needed / 7 # Spread savings over 7 days
|
| 51 |
+
new_habits = {day: max(0, amount - daily_savings) for day, amount in habits_dict.items()}
|
| 52 |
+
|
| 53 |
+
# Format the new habits into a readable string
|
| 54 |
+
new_habits_str = ', '.join([f"{day}: ${amount:.2f}" for day, amount in new_habits.items()])
|
| 55 |
+
|
| 56 |
+
return (
|
| 57 |
+
f"To achieve your goal of {goal} within the {period}, you need to save an additional ${savings_needed:.2f}.\n"
|
| 58 |
+
f"Consider adjusting your daily spending habits as follows:\n"
|
| 59 |
+
f"{new_habits_str}\n"
|
| 60 |
+
f"This will help you stay on track with your financial goals."
|
| 61 |
+
)
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
# Example usage:
|
| 65 |
+
print(finance_management_plan(1000.0, "Monday: $50, Tuesday: $30, Wednesday: $40, Thursday: $20, Friday: $60, Saturday: $80, Sunday: $70", "Save $500 for a vacation", "month"))
|
| 66 |
|
| 67 |
@tool
|
| 68 |
def get_current_time_in_timezone(timezone: str) -> str:
|