zayeem00 commited on
Commit
ee99a01
1 Parent(s): 35b73c1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +67 -38
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
- env = environ.Env()
7
- environ.Env.read_env()
8
- API_KEY = env("apikey")
9
- openai.api_key = API_KEY
10
-
11
- def financial_planning(prompt):
12
- response = openai.chat.completions.create(
13
- model="gpt-3.5-turbo-16k",
14
- messages=prompt,
 
 
15
  max_tokens=500,
16
  temperature=0.7,
17
  )
18
- return response.choices[0].text.strip()
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
- iface = gr.Interface(
49
- fn=generate_advice,
50
- inputs=["text", "number", "number", "number", "number", "number", "text",
51
- gr.Radio(["Low", "Medium", "High"],label="Risk Tolerance"),
52
- gr.Number(label="Retirement Age"),
53
- gr.Number(label="Retirement Savings Goal"),
54
- gr.Textbox(label="Short-term Goals (comma separated)"),
55
- gr.Textbox(label="Long-term Goals (comma separated)"),
56
- gr.Number(label="Dependents"),
57
- gr.Number(label="Monthly Health Expenses"),
58
- gr.Number(label="Monthly Education Expenses"),
59
- gr.Textbox(label="Insurance Policies (comma separated)"),
60
- gr.Textbox(label="Major Purchases (with estimated costs, comma separated)"),
61
- gr.Number(label="Emergency Fund"),
62
- gr.Number(label="Annual Income Growth (%)"),
63
- gr.Number(label="Annual Expense Growth (%)"),
64
- gr.Dropdown(label="Currency", choices=["USD", "EUR", "GBP", "JPY", "INR", "AUD", "CAD", "CHF", "CNY", "Other"]),
65
- ],
66
- outputs="text",
67
- title="Smart Finance Planner: Your Personalized Financial Guide",
68
- description="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!"
69
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
 
71
- iface.launch()
 
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()