antonioneto11 commited on
Commit
69e3a12
·
verified ·
1 Parent(s): 22a49c4
Files changed (1) hide show
  1. app.py +52 -0
app.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import openai
3
+
4
+ # Replace 'your_openai_api_key_here' with your actual OpenAI API key.
5
+ openai.api_key = 'OPEN_AI_KEY'
6
+
7
+ def generate_response(question):
8
+ try:
9
+ # Make a call to OpenAI's Chat Completion API to generate a response based on the user's question.
10
+
11
+ response = openai.ChatCompletion.create(
12
+ model="gpt-3.5-turbo", # Specify the chat model you are using
13
+ messages=[
14
+ # {"role": "system", "content": "You are a financial advisor providing clear, actionable advice .. Maintain a friendly and empathetic tone, aiming to educate and empower users with financial knowledge"},
15
+
16
+ {"role": "system", "content": "You are a highly knowledgeable and empathetic financial advisor. Your primary role is to provide comprehensive advice on personal finance topics, including but not limited to saving, investing, debt management, retirement planning, and budgeting. Your advice should be actionable, with clear steps or considerations that users can follow to improve their financial health. Always maintain a friendly and supportive tone, aiming to demystify financial concepts and empower users to make informed decisions. Where possible, tailor your advice to fit a variety of financial situations, emphasizing the importance of context in financial planning. Remember, your goal is to educate and inspire confidence, making complex financial decisions approachable and understandable."},
17
+ {"role": "user", "content": question},
18
+ # {
19
+ # "role": "system",
20
+ # "content": "You are an AI financial Advisor designed to provide thoughtful, comprehensive answers. Take your time to consider each question deeply before responding. Your goal is to educate and provide value, focusing on quality and depth. Please structure your responses to start with a brief overview of the topic, delve into a detailed analysis, and conclude with a summary or actionable advice if applicable. Reflect on the question from multiple angles and provide insights that might not be immediately obvious, aiming to offer a well-rounded perspective."},
21
+
22
+
23
+
24
+
25
+
26
+ # {"role": "system", "content": "You are a financial advisor providing clear, actionable advice. Offer guidance that is detailed, practical, and understandable, using bullet points for actionable steps whenever possible. Maintain a friendly and empathetic tone, aiming to educate and empower users with financial knowledge"},
27
+ # {"role": "system", "content": "You are a financial planning advisor providing clear, actionable advice on various topics like saving for retirement, reducing debt, budgeting, investing, and improving credit scores. Offer guidance that is detailed, practical, and understandable, using bullet points for actionable steps whenever possible. Maintain a friendly and empathetic tone, aiming to educate and empower users with financial knowledge"},
28
+
29
+ ]
30
+ )
31
+ return response.choices[0].message['content'].strip()
32
+ except Exception as e:
33
+ print(f"Error generating response: {e}")
34
+ return "I'm sorry, I can't process your request now. Please try again later."
35
+
36
+ def chat_with_bot(user_question):
37
+ return generate_response(user_question)
38
+
39
+ def main():
40
+ interface = gr.Interface(
41
+ fn=chat_with_bot,
42
+ inputs=gr.Textbox(lines=2, placeholder="Type your financial question here..."),
43
+ outputs="text",
44
+ title="Financial Assistant Chatbot",
45
+ description="Ask any financial question, and I'll do my best to provide helpful advice using AI."
46
+ )
47
+ interface.launch()
48
+
49
+ if __name__ == '__main__':
50
+ # Correctly set up the interface to expect a single output
51
+ iface = gr.Interface(fn=chat_with_bot, inputs="text", outputs="text")
52
+ iface.launch(share=True)