Great! It looks like you're building a prototype AI chatbot for financial analysis using Python, with a focus on simplicity and predefined queries.
Below, I’ll provide a complete, working example of your chatbot, as well as testing tips and documentation you can include in your final deliverables. Let's walk through each step accordingly.
✅ Step 1: Preparation
Dependencies (install if using a virtual environment or fresh machine):
pip install pandas flask
Sample analyzed financial dataset (you may already have this, but here’s a mockup for testing):
# sample_data_analysis.py
# Normally you'd import real processed data here, but we define static values for simplicity
financial_data = {
"total_revenue": "$5,000,000",
"net_income_change": "increased",
"net_income_variation": "$500,000",
"top_expense_category": "Research and Development",
"operating_margin": "15%"
}
✅ Step 2 & 3: Chatbot Design & Code
simple_chatbot.py
from sample_data_analysis import financial_data
def simple_chatbot(user_query):
if user_query.lower() == "what is the total revenue?":
return f"The total revenue is {financial_data['total_revenue']}."
elif user_query.lower() == "how has net income changed over the last year?":
return f"The net income has {financial_data['net_income_change']} by {financial_data['net_income_variation']} over the last year."
elif user_query.lower() == "what is the top expense category?":
return f"The top expense category is {financial_data['top_expense_category']}."
elif user_query.lower() == "what is the operating margin?":
return f"The current operating margin is {financial_data['operating_margin']}."
else:
return "Sorry, I can only provide information on predefined queries."
# For command-line testing
if __name__ == "__main__":
print("Welcome to the Financial Chatbot. Ask your question:")
while True:
user_input = input("You: ")
if user_input.lower() in ["exit", "quit"]:
print("Chatbot: Goodbye!")
break
response = simple_chatbot(user_input)
print(f"Chatbot: {response}")
✅ Test Example (optional)
Run python simple_chatbot.py in the terminal and test with:
What is the total revenue?
How has net income changed over the last year?
What is the top expense category?
Unknown query