Spaces:
Sleeping
Sleeping
import gradio as gr | |
import openai | |
from transformers import pipeline | |
import environ | |
env = environ.Env() | |
environ.Env.read_env() | |
API_KEY = env("apikey") | |
openai.api_key = API_KEY | |
def financial_planning(prompt): | |
response = openai.chat.completions.create( | |
model="gpt-3.5-turbo-16k", | |
messages=prompt, | |
max_tokens=500, | |
temperature=0.7, | |
) | |
return response.choices[0].text.strip() | |
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): | |
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) | |
return advice | |
iface = gr.Interface( | |
fn=generate_advice, | |
inputs=["text", "number", "number", "number", "number", "number", "text", | |
gr.Radio(["Low", "Medium", "High"],label="Risk Tolerance"), | |
gr.Number(label="Retirement Age"), | |
gr.Number(label="Retirement Savings Goal"), | |
gr.Textbox(label="Short-term Goals (comma separated)"), | |
gr.Textbox(label="Long-term Goals (comma separated)"), | |
gr.Number(label="Dependents"), | |
gr.Number(label="Monthly Health Expenses"), | |
gr.Number(label="Monthly Education Expenses"), | |
gr.Textbox(label="Insurance Policies (comma separated)"), | |
gr.Textbox(label="Major Purchases (with estimated costs, comma separated)"), | |
gr.Number(label="Emergency Fund"), | |
gr.Number(label="Annual Income Growth (%)"), | |
gr.Number(label="Annual Expense Growth (%)"), | |
gr.Dropdown(label="Currency", choices=["USD", "EUR", "GBP", "JPY", "INR", "AUD", "CAD", "CHF", "CNY", "Other"]), | |
], | |
outputs="text", | |
title="Smart Finance Planner: Your Personalized Financial Guide", | |
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!" | |
) | |
iface.launch() | |