Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,24 +1,23 @@
|
|
1 |
import gradio as gr
|
2 |
import openai
|
3 |
-
from transformers import pipeline
|
4 |
-
import environ
|
5 |
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
|
|
|
|
15 |
max_tokens=500,
|
16 |
temperature=0.7,
|
17 |
)
|
18 |
-
return response.choices[0]
|
19 |
-
|
20 |
|
21 |
-
def generate_advice(name, age, income, expenses, savings, debts, investment_preferences, risk_tolerance, retirement_age, retirement_savings_goal, short_term_goals, long_term_goals, dependents, health_expenses, education_expenses, insurance_policies, major_purchases, emergency_fund, annual_income_growth, annual_expense_growth, currency):
|
22 |
prompt = (
|
23 |
f"Name: {name}\n"
|
24 |
f"Age: {age}\n"
|
@@ -42,30 +41,60 @@ def generate_advice(name, age, income, expenses, savings, debts, investment_pref
|
|
42 |
f"Annual Expense Growth: {annual_expense_growth}%\n"
|
43 |
f"Provide a detailed financial plan based on the above information."
|
44 |
)
|
45 |
-
advice = financial_planning(prompt)
|
46 |
return advice
|
47 |
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
|
71 |
-
|
|
|
1 |
import gradio as gr
|
2 |
import openai
|
|
|
|
|
3 |
|
4 |
+
def financial_planning(prompt, api_key):
|
5 |
+
|
6 |
+
openai.api_key = api_key
|
7 |
+
|
8 |
+
message=[
|
9 |
+
{"role": "system", "content": "You are a knowledgeable and insightful Financial Planner dedicated to helping users make informed investment decisions based on their unique financial profiles."},
|
10 |
+
{"role": "user", "content": prompt}
|
11 |
+
]
|
12 |
+
response = openai.ChatCompletion.create(
|
13 |
+
model="gpt-4o",
|
14 |
+
messages= message,
|
15 |
max_tokens=500,
|
16 |
temperature=0.7,
|
17 |
)
|
18 |
+
return response.choices[0]["message"]["content"]
|
|
|
19 |
|
20 |
+
def generate_advice(name, age, income, expenses, savings, debts, investment_preferences, risk_tolerance, retirement_age, retirement_savings_goal, short_term_goals, long_term_goals, dependents, health_expenses, education_expenses, insurance_policies, major_purchases, emergency_fund, annual_income_growth, annual_expense_growth, currency, api_key):
|
21 |
prompt = (
|
22 |
f"Name: {name}\n"
|
23 |
f"Age: {age}\n"
|
|
|
41 |
f"Annual Expense Growth: {annual_expense_growth}%\n"
|
42 |
f"Provide a detailed financial plan based on the above information."
|
43 |
)
|
44 |
+
advice = financial_planning(prompt, api_key)
|
45 |
return advice
|
46 |
|
47 |
+
# Function to clear inputs
|
48 |
+
def clear_inputs():
|
49 |
+
return "", 0, 0, 0, 0, 0, "", "Low", 0, 0, "", "", 0, 0, 0, "", "", 0, 0, 0, "HKD"
|
50 |
+
|
51 |
+
|
52 |
+
with gr.Blocks(gr.themes.Base()) as demo:
|
53 |
+
gr.Markdown("<h1 style='text-align: center'>Smart Finance Planner: Your Personalized Financial Guide</h1>")
|
54 |
+
gr.Markdown("<p style='text-align: center'>Unlock your financial potential with Smart Finance Planner. Input your financial details and receive a customized, comprehensive financial plan tailored to your goals and lifestyle. Whether you're planning for retirement, saving for a major purchase, or just looking to optimize your investments, our intelligent tool provides expert advice to help you achieve financial success. Get started today and take control of your financial future!</p>")
|
55 |
+
|
56 |
+
|
57 |
+
with gr.Row():
|
58 |
+
name = gr.Textbox(label="Name")
|
59 |
+
age = gr.Number(label="Age")
|
60 |
+
income = gr.Textbox(label="Monthly Income")
|
61 |
+
expenses = gr.Textbox(label="Monthly Expenses")
|
62 |
+
savings = gr.Textbox(label="Savings", placeholder = "Overall Savings")
|
63 |
+
debts = gr.Textbox(label="Debts", placeholder="Current Debts")
|
64 |
+
investment_preferences = gr.Textbox(label="Investment Preferences")
|
65 |
+
risk_tolerance = gr.Dropdown(label="Risk Tolerance", choices=["Low", "Medium", "High"])
|
66 |
+
retirement_age = gr.Number(label="Retirement Age")
|
67 |
+
retirement_savings_goal = gr.Textbox(label="Retirement Savings Goal")
|
68 |
+
short_term_goals = gr.Textbox(label="Short-term Goals", placeholder="Comma separated")
|
69 |
+
long_term_goals = gr.Textbox(label="Long-term Goals", placeholder="Comma separated")
|
70 |
+
dependents = gr.Number(label="Dependents")
|
71 |
+
health_expenses = gr.Textbox(label="Monthly Health Expenses")
|
72 |
+
education_expenses = gr.Textbox(label="Education Expenses", placeholder= "Monthly Expense")
|
73 |
+
insurance_policies = gr.Textbox(label="Insurance Policies", placeholder="Comma separated")
|
74 |
+
major_purchases = gr.Textbox(label="Major Purchases", placeholder="Enter estimated costs")
|
75 |
+
emergency_fund = gr.Textbox(label="Emergency Fund")
|
76 |
+
annual_income_growth = gr.Textbox(label="Annual Income Growth", placeholder="In %")
|
77 |
+
annual_expense_growth = gr.Textbox(label="Annual Expense Growth", placeholder="In %")
|
78 |
+
currency = gr.Dropdown(label="Currency", choices=["HKD", "USD", "EUR", "GBP", "JPY", "INR", "AUD", "CAD", "CHF", "CNY", "Other"])
|
79 |
+
|
80 |
+
with gr.Row():
|
81 |
+
api_key = gr.Textbox(label='OpenAI API Key', type='password')
|
82 |
+
|
83 |
+
with gr.Row():
|
84 |
+
submit_btn = gr.Button("Generate Financial Plan")
|
85 |
+
clear_btn = gr.Button("Clear")
|
86 |
+
|
87 |
+
with gr.Row():
|
88 |
+
output = gr.Markdown("<style='text-align: center'>",label="Financial Plan")
|
89 |
+
|
90 |
+
submit_btn.click(
|
91 |
+
generate_advice,
|
92 |
+
inputs=[name, age, income, expenses, savings, debts, investment_preferences, risk_tolerance, retirement_age, retirement_savings_goal, short_term_goals, long_term_goals, dependents, health_expenses, education_expenses, insurance_policies, major_purchases, emergency_fund, annual_income_growth, annual_expense_growth, currency, api_key],
|
93 |
+
outputs=output
|
94 |
+
)
|
95 |
+
clear_btn.click(
|
96 |
+
clear_inputs,
|
97 |
+
outputs=[name, age, income, expenses, savings, debts, investment_preferences, risk_tolerance, retirement_age, retirement_savings_goal, short_term_goals, long_term_goals, dependents, health_expenses, education_expenses, insurance_policies, major_purchases, emergency_fund, annual_income_growth, annual_expense_growth, currency]
|
98 |
+
)
|
99 |
|
100 |
+
demo.launch()
|