Spaces:
Sleeping
Sleeping
bug fixes + adding goal tracker
Browse files
app.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
import os
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
from sentence_transformers import SentenceTransformer
|
| 4 |
import torch
|
|
@@ -99,20 +100,6 @@ body {
|
|
| 99 |
background-color: #52528C !important;
|
| 100 |
}
|
| 101 |
"""
|
| 102 |
-
|
| 103 |
-
with gr.Blocks(css=custom_css) as demo:
|
| 104 |
-
gr.Image("banner_image.png", show_label=False, container=False)
|
| 105 |
-
|
| 106 |
-
gr.ChatInterface(
|
| 107 |
-
respond,
|
| 108 |
-
title="Student Formula Bot 🔬",
|
| 109 |
-
description='Welcome to the core component of \"The Student Formula\": the RAG chatbot! With the ability to act as a finance tutor, accountability buddy, and goal-setting partner all in one, it\'s designed to best suit your needs on the way to productivity and success. To get started, ask about the basic principles of creating a budget!',
|
| 110 |
-
examples=[
|
| 111 |
-
"How do I build and balance a budget?",
|
| 112 |
-
"Why do people write SMART goals?",
|
| 113 |
-
"What is educational investment?"
|
| 114 |
-
]
|
| 115 |
-
)
|
| 116 |
|
| 117 |
gr.HTML(
|
| 118 |
"""
|
|
@@ -143,11 +130,72 @@ def budgetCalculator(income):
|
|
| 143 |
f"Based on a monthly income of ${income:,.2f}."
|
| 144 |
)
|
| 145 |
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 152 |
|
| 153 |
demo.launch()
|
|
|
|
| 1 |
import os
|
| 2 |
+
import datetime
|
| 3 |
import gradio as gr
|
| 4 |
from sentence_transformers import SentenceTransformer
|
| 5 |
import torch
|
|
|
|
| 100 |
background-color: #52528C !important;
|
| 101 |
}
|
| 102 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
|
| 104 |
gr.HTML(
|
| 105 |
"""
|
|
|
|
| 130 |
f"Based on a monthly income of ${income:,.2f}."
|
| 131 |
)
|
| 132 |
|
| 133 |
+
def goalTracker(goal, savings, targetDate):
|
| 134 |
+
if goal is None or savings is None or not targetDate:
|
| 135 |
+
return "Please fill in the tracker to get started!"
|
| 136 |
+
if goal <= 0:
|
| 137 |
+
return "Set your goal for higher than 0!"
|
| 138 |
+
if savings < 0:
|
| 139 |
+
return "Savings can't be negative; start at 0 if needed!"
|
| 140 |
+
|
| 141 |
+
try:
|
| 142 |
+
target = datetime.datetime.strptime(targetDate, "%Y-%m-%d").date()
|
| 143 |
+
except ValueError:
|
| 144 |
+
return "Please enter the date in YYYY-MM-DD format! (ex: 2026-06-12)"
|
| 145 |
+
|
| 146 |
+
today = datetime.date.today()
|
| 147 |
+
daysLeft = (targetDate - today).days()
|
| 148 |
+
|
| 149 |
+
if daysLeft <= 0:
|
| 150 |
+
return "Try to set your goal for sometime in the future!"
|
| 151 |
+
|
| 152 |
+
remaining = goal - savings
|
| 153 |
+
if remaining <= 0:
|
| 154 |
+
return "Congratulations on hitting your goal!"
|
| 155 |
+
|
| 156 |
+
weeklyAmount = remaining / (daysLeft / 7)
|
| 157 |
+
monthlyAmount = remaining / (daysLeft / 30.44)
|
| 158 |
+
|
| 159 |
+
return (
|
| 160 |
+
f"### Goal Tracker Results\n\n"
|
| 161 |
+
f"- **Amount Remaining:** ${remaining:,.2f}\n"
|
| 162 |
+
f"- **Days Remaining:** ${daysLeft:,.2f}\n"
|
| 163 |
+
f"- **Save this much per week:** ${weeklyAmount:,.2f}\n"
|
| 164 |
+
f"- **Save this much per month:** ${monthlyAmount:,.2f}\n"
|
| 165 |
+
)
|
| 166 |
+
|
| 167 |
+
with gr.Blocks(css=custom_css) as demo:
|
| 168 |
+
gr.Image("banner_image.png", show_label=False, container=False)
|
| 169 |
+
|
| 170 |
+
with gr.Tabs():
|
| 171 |
+
with gr.Tab("Chatbot"):
|
| 172 |
+
gr.ChatInterface(
|
| 173 |
+
respond,
|
| 174 |
+
title="Student Formula Bot 🔬",
|
| 175 |
+
description='Welcome to the core component of \"The Student Formula\": the RAG chatbot! With the ability to act as a finance tutor, accountability buddy, and goal-setting partner all in one, it\'s designed to best suit your needs on the way to productivity and success. To get started, ask about the basic principles of creating a budget!',
|
| 176 |
+
examples=[
|
| 177 |
+
"How do I build and balance a budget?",
|
| 178 |
+
"Why do people write SMART goals?",
|
| 179 |
+
"What is educational investment?"
|
| 180 |
+
]
|
| 181 |
+
)
|
| 182 |
+
|
| 183 |
+
with gr.Tab("Budget Calculator"):
|
| 184 |
+
gr.Markdown("## 50/30/20 Budget Calculator")
|
| 185 |
+
gr.Markdown("Want to see what your monthly budget might look like when following financial literacy principles? Enter your monthly income to see the suggested breakdown!")
|
| 186 |
+
incomeInput = gr.Number(label = "Monthly Income ($))", minimum = 0)
|
| 187 |
+
budgetOutput = gr.Markdown(label = "Monthly Budget"),
|
| 188 |
+
budgetButton = gr.Button("Calculate")
|
| 189 |
+
budgetButton.click(fn = budgetCalculator, inputs = incomeInput, outputs = budgetOutput)
|
| 190 |
+
|
| 191 |
+
with gr.Tab("Goal Tracker"):
|
| 192 |
+
gr.Markdown("## Savings Goal Tracker")
|
| 193 |
+
gr.Markdown("Saving up to buy something special? Want to figure out how long it'll take to reach that goal? Enter your goal amount, current savings, and target date to see the suggested timeline!")
|
| 194 |
+
goalInput = gr.Number(label = "Savings Goal ($)", minimum = 0),
|
| 195 |
+
savingsInput = gr.Number(label = "Current Savings ($)", minimum = 0),
|
| 196 |
+
targetInput = gr.Textbox(label = "Target Date (YYYY-MM-DD", placeholder = "2026-12-31")
|
| 197 |
+
goalOutput = gr.Markdown(label = "Your Savings Plan")
|
| 198 |
+
goalButton = gr.Button("Calculate")
|
| 199 |
+
goalButton.click(fn = goalTracker, inputs = [goalInput, savingsInput, targetInput], outputs = goalOutput)
|
| 200 |
|
| 201 |
demo.launch()
|