Spaces:
Sleeping
Sleeping
license: apache-2.0 | |
title: Fin Analyst | |
sdk: streamlit | |
emoji: π | |
colorFrom: green | |
colorTo: green | |
# FinBuddy Project | |
## Overview | |
FinBuddy is an AI Assistant designed to help users with questions related to financial metrics of Microsoft (MSFT), Tesla (TSLA), and Apple (AAPL). The project uses a combination of rule-based logic and machine learning models to provide answers in different formats such as text responses, tables, and charts. The application is built using Streamlit for the user interface and integrates with LangChain and Groq for the underlying AI functionalities. | |
## Project Structure | |
The project consists of three main components: | |
1. **main.py**: This script handles the core functionalities of the AI assistant, including initializing the language models, creating agents, and defining the conversation handling logic. | |
2. **rule_based.py**: This script contains the rule-based logic for providing predefined answers to specific queries. | |
3. **app.py**: This script sets up the Streamlit interface and integrates the rule-based and AI-driven responses. | |
## File Descriptions | |
### `main.py` | |
- **Imports and Initialization**: Sets up necessary imports, initializes the Groq client and model, and defines chat history. | |
- **Agent Creation**: Creates a CSV agent using LangChain's `create_csv_agent` function to handle queries related to financial metrics. | |
- **Functions**: | |
- `convo_agent`: Handles simple conversational queries. | |
- `csv_agent`: Processes financial queries and formats responses as tables, bar charts, or line charts. | |
- `run_conversation`: Manages the flow of the conversation by determining which function to use based on the user query. | |
- `get_response`: Processes the user query, interacts with the agents, and returns the appropriate response. | |
- `write_answer`: Formats and displays the response in Streamlit, including rendering tables and charts. | |
### `rule_based.py` | |
- **simple_chatbot**: A simple rule-based chatbot that returns predefined answers for specific queries related to the total revenue of MSFT, AAPL, and TSLA for 2022 and 2023. | |
### `app.py` | |
- **Streamlit Setup**: Initializes the Streamlit app, sets the title, and displays chat history. | |
- **Message Handling**: Captures user input, retrieves responses from the AI assistant or rule-based bot, and displays the responses. | |
- **Integration**: Integrates `get_response` from `main.py` and `simple_chatbot` from `rule_based.py` to handle user queries. | |
## Project Flow | |
1. **User Interaction**: | |
- The user interacts with the Streamlit app by typing a query into the chat input. | |
2. **Message Capture**: | |
- The app captures the user's input and appends it to the chat history. | |
3. **Response Generation**: | |
- The `get_response` function is called with the user query. | |
- `get_response` decides whether to use the `convo_agent` or `csv_agent` based on the nature of the query. | |
- The appropriate agent processes the query and returns the response. | |
4. **Rule-Based Check**: | |
- Optionally, the response can be generated by the `simple_chatbot` for predefined queries if the rule-based option is enabled. | |
5. **Response Display**: | |
- The response is formatted and displayed in the Streamlit app. | |
- If the response includes a table or chart, it is rendered accordingly. | |
6. **Chat History Update**: | |
- The chat history is updated with the new user query and the AI response. | |
## How to Run | |
Configuring Groq API | |
Create an API Key: | |
Visit the [Groq Console](https://console.groq.com/docs/api-reference#chat) and create an API key. | |
1. Ensure you have the necessary dependencies installed: | |
```bash | |
pip install -r requirements.txt | |
``` | |
2. Run the Streamlit app: | |
```bash | |
streamlit run app.py | |
``` | |
3. Interact with the FinBuddy assistant through the Streamlit interface by typing queries related to the financial metrics of MSFT, TSLA, and AAPL. | |
Current this doesn't support Visualization or table, will be added in next iteration. | |
## Conclusion | |
FinBuddy is a robust AI assistant designed to help users with financial queries. By combining rule-based logic and advanced AI models, it provides accurate and formatted responses to a variety of questions. The use of Streamlit ensures a user-friendly interface for seamless interaction. |