Great! You're ready to create a simplified chatbot prototype for financial analysis. Let’s walk through the process step by step, and then I’ll provide you with a complete example that you can use for your submission.
🧠 Step 1: Preparation
1.1 Review the Analyzed Data
Assuming you analyzed financial data in Task 1, let’s say the results looked like this:
| Metric | Value (in USD) | Change (YoY) |
|---|
| Total Revenue | 500,000 | +12% |
| Net Income | 75,000 | -5% |
| Operating Expenses | 200,000 | +3% |
We’ll use these values to craft our canned responses.
1.2 Set Up Your Environment
Ensure you have Python installed. No external libraries are required for this basic version, but you can use pandas if you want to load data dynamically.
🛠️ Step 2: Chatbot Design & Data Preparation
2.1 Define Predefined Queries
Here are 4 predefined queries we’ll support:
- "What is the total revenue?"
- "How has net income changed over the last year?"
- "What are the operating expenses?"
- "What is the net income?"
2.2 Prepare Canned Responses
Based on the sample data:
- Total Revenue: $500,000 (+12% YoY)
- Net Income: $75,000 (-5% YoY)
- Operating Expenses: $200,000 (+3% YoY)
🧪 Step 3: Basic Chatbot Development
Below is a simple Python script using if-elif-else logic:
def financial_chatbot(user_query):
if user_query == "What is the total revenue?":
return "The total revenue is $500,000, which represents a 12% increase compared to last year."
elif user_query == "How has net income changed over the last year?":
return "The net income has decreased by 5% over the last year and is currently $75,000."
elif user_query == "What are the operating expenses?":
return "The operating expenses are $200,000, showing a 3% increase from the previous year."
elif user_query == "What is the net income?":
return "The current net income is $75,000."
else:
return "Sorry, I can only answer predefined financial questions. Please try one of the following:\n" \
"- What is the total revenue?\n" \
"- How has net income changed over the last year?\n" \
"- What are the operating expenses?\n" \
"- What is the net income?"
# Interactive loop for testing
if __name__ == "__main__":
print("Welcome to the Financial Chatbot! Type 'exit' to quit.")
while True:
user_input = input("You: ")
if user_input.lower() == "exit":
print("Chatbot: Goodbye!")
break
response = financial_chatbot(user_input)
print("Chatbot:", response)