import gradio as gr from model.py import financial_planning 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): prompt = ( f"Name: {name}\n" f"Age: {age}\n" f"Monthly Income: {currency}{income}\n" f"Monthly Expenses: {currency}{expenses}\n" f"Savings: {currency}{savings}\n" f"Debts: {currency}{debts}\n" f"Investment Preferences: {investment_preferences}\n" f"Risk Tolerance: {risk_tolerance}\n" f"Retirement Age: {retirement_age}\n" f"Retirement Savings Goal: {currency}{retirement_savings_goal}\n" f"Short-term Goals: {short_term_goals}\n" f"Long-term Goals: {long_term_goals}\n" f"Dependents: {dependents}\n" f"Health Expenses: {currency}{health_expenses}\n" f"Education Expenses: {currency}{education_expenses}\n" f"Insurance Policies: {insurance_policies}\n" f"Major Purchases: {major_purchases}\n" f"Emergency Fund: {currency}{emergency_fund}\n" f"Annual Income Growth: {annual_income_growth}%\n" f"Annual Expense Growth: {annual_expense_growth}%\n" f"Provide a detailed financial plan based on the above information." ) advice = financial_planning(prompt, api_key) return advice # Function to clear inputs def clear_inputs(): return "", 0, 0, 0, 0, 0, "", "Low", 0, 0, "", "", 0, 0, 0, "", "", 0, 0, 0, "HKD" with gr.Blocks(gr.themes.Base()) as demo: gr.Markdown("
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!
") with gr.Row(): name = gr.Textbox(label="Name") age = gr.Number(label="Age") income = gr.Textbox(label="Monthly Income") expenses = gr.Textbox(label="Monthly Expenses") savings = gr.Textbox(label="Savings", placeholder = "Overall Savings") debts = gr.Textbox(label="Debts", placeholder="Current Debts") investment_preferences = gr.Textbox(label="Investment Preferences") risk_tolerance = gr.Dropdown(label="Risk Tolerance", choices=["Low", "Medium", "High"]) retirement_age = gr.Number(label="Retirement Age") retirement_savings_goal = gr.Textbox(label="Retirement Savings Goal") short_term_goals = gr.Textbox(label="Short-term Goals", placeholder="Comma separated") long_term_goals = gr.Textbox(label="Long-term Goals", placeholder="Comma separated") dependents = gr.Number(label="Dependents") health_expenses = gr.Textbox(label="Monthly Health Expenses") education_expenses = gr.Textbox(label="Education Expenses", placeholder= "Monthly Expense") insurance_policies = gr.Textbox(label="Insurance Policies", placeholder="Comma separated") major_purchases = gr.Textbox(label="Major Purchases", placeholder="Enter estimated costs") emergency_fund = gr.Textbox(label="Emergency Fund") annual_income_growth = gr.Textbox(label="Annual Income Growth", placeholder="In %") annual_expense_growth = gr.Textbox(label="Annual Expense Growth", placeholder="In %") currency = gr.Dropdown(label="Currency", choices=["HKD", "USD", "EUR", "GBP", "JPY", "INR", "AUD", "CAD", "CHF", "CNY", "Other"]) with gr.Row(): api_key = gr.Textbox(label='OpenAI API Key', type='password') with gr.Row(): submit_btn = gr.Button("Generate Financial Plan") clear_btn = gr.Button("Clear") with gr.Row(): output = gr.Markdown(label="Financial Plan") submit_btn.click( generate_advice, 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], outputs=output ) clear_btn.click( clear_inputs, 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] ) demo.launch()