├── .gitignore ├── LICENSE ├── README.md ├── agents.py ├── app.py ├── requirements.txt ├── tasks.py └── tools.py /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | share/python-wheels/ 24 | *.egg-info/ 25 | .installed.cfg 26 | *.egg 27 | MANIFEST 28 | 29 | # PyInstaller 30 | # Usually these files are written by a python script from a template 31 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 32 | *.manifest 33 | *.spec 34 | 35 | # Installer logs 36 | pip-log.txt 37 | pip-delete-this-directory.txt 38 | 39 | # Unit test / coverage reports 40 | htmlcov/ 41 | .tox/ 42 | .nox/ 43 | .coverage 44 | .coverage.* 45 | .cache 46 | nosetests.xml 47 | coverage.xml 48 | *.cover 49 | *.py,cover 50 | .hypothesis/ 51 | .pytest_cache/ 52 | cover/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | .pybuilder/ 76 | target/ 77 | 78 | # Jupyter Notebook 79 | .ipynb_checkpoints 80 | 81 | # IPython 82 | profile_default/ 83 | ipython_config.py 84 | 85 | # pyenv 86 | # For a library or package, you might want to ignore these files since the code is 87 | # intended to run in multiple environments; otherwise, check them in: 88 | # .python-version 89 | 90 | # pipenv 91 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 92 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 93 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 94 | # install all needed dependencies. 95 | #Pipfile.lock 96 | 97 | # poetry 98 | # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. 99 | # This is especially recommended for binary packages to ensure reproducibility, and is more 100 | # commonly ignored for libraries. 101 | # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control 102 | #poetry.lock 103 | 104 | # pdm 105 | # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. 106 | #pdm.lock 107 | # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it 108 | # in version control. 109 | # https://pdm.fming.dev/#use-with-ide 110 | .pdm.toml 111 | 112 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm 113 | __pypackages__/ 114 | 115 | # Celery stuff 116 | celerybeat-schedule 117 | celerybeat.pid 118 | 119 | # SageMath parsed files 120 | *.sage.py 121 | 122 | # Environments 123 | .env 124 | .venv 125 | env/ 126 | venv/ 127 | ENV/ 128 | env.bak/ 129 | venv.bak/ 130 | 131 | # Spyder project settings 132 | .spyderproject 133 | .spyproject 134 | 135 | # Rope project settings 136 | .ropeproject 137 | 138 | # mkdocs documentation 139 | /site 140 | 141 | # mypy 142 | .mypy_cache/ 143 | .dmypy.json 144 | dmypy.json 145 | 146 | # Pyre type checker 147 | .pyre/ 148 | 149 | # pytype static type analyzer 150 | .pytype/ 151 | 152 | # Cython debug symbols 153 | cython_debug/ 154 | 155 | # PyCharm 156 | # JetBrains specific template is maintained in a separate JetBrains.gitignore that can 157 | # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore 158 | # and can be added to the global gitignore or merged into this file. For a more nuclear 159 | # option (not recommended) you can uncomment the following to ignore the entire idea folder. 160 | #.idea/ 161 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 Prathmesh Rane 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Market-Research-Agent 2 | 3 | ## Description 4 | 5 | The objective of this application is to assist users in performing comprehensive financial and market analyses of any company using publicly available information from the internet. The application employs multiple AI agents, each specialized in different aspects of financial and market research, to gather, analyze, and compile data into a cohesive and informative report. This tool enhances the user's ability to make informed decisions based on detailed and factual analysis. Key technologies used in this project include CrewAi,Langchain, Streamlit, Python and Google Gemini Flash 1.5 LLM 6 | 7 | ## Demo of the app 8 | 9 | https://github.com/psrane8/Market-Research-Agent/assets/49234060/2ecdf874-420a-48db-a4b2-411e3424cd28 10 | 11 | ## Installation 12 | 13 | To run this project, follow these steps: 14 | 15 | 1. Clone this repository to your local machine. 16 | ```bash 17 | git clone [https://github.com/psrane8/Market-Research-Agent.git] 18 | ``` 19 | 20 | 2. Navigate to the project directory. 21 | ```bash 22 | cd Market-Research-Agent 23 | ``` 24 | 25 | 3. Install the required dependencies. 26 | ```bash 27 | pip install -r requirements.txt 28 | ``` 29 | 30 | ## Usage 31 | 32 | 1. Ensure you have installed all dependencies as instructed above. 33 | 34 | 2. Run the Streamlit app. 35 | ```bash 36 | streamlit run app.py 37 | ``` 38 | 39 | 3. Access the app through your browser at http://localhost:8501 40 | 41 | 4. Create a .env file consisting of "GOOGLE_API_KEY" and "SERPER_API_KEY" 42 | 43 | 5. Type the name of the company and watch the report being created 44 | 45 | 46 | ## Credits 47 | 48 | - [CrewAI](https://www.crewai.com/) 49 | - [Langchain](https://www.langchain.com/) 50 | - [Google Gemini Flash 1.5](https://deepmind.google/technologies/gemini/flash/) 51 | - [Streamlit](https://streamlit.io/) 52 | - [SerperAPI](https://serper.dev/) 53 | - [Python](https://www.python.org/) 54 | 55 | ## License 56 | 57 | This project is licensed under the [MIT License](LICENSE). 58 | ``` 59 | -------------------------------------------------------------------------------- /agents.py: -------------------------------------------------------------------------------- 1 | from crewai import Agent 2 | import os 3 | from dotenv import load_dotenv 4 | from langchain_google_genai import ChatGoogleGenerativeAI 5 | from langchain_openai import OpenAI 6 | from tools import tool 7 | 8 | load_dotenv() 9 | import asyncio 10 | 11 | try: 12 | loop = asyncio.get_running_loop() 13 | except RuntimeError: 14 | loop = asyncio.new_event_loop() 15 | asyncio.set_event_loop(loop) 16 | #Defining the base llm model 17 | llm=ChatGoogleGenerativeAI(model="gemini-1.5-flash", 18 | google_api_key=os.environ.get("GOOGLE_API_KEY"), 19 | temperature=0.5, 20 | verbose=True) 21 | 22 | 23 | #Market research analyst agent 24 | market_research_analyst= Agent( 25 | role="Market Research Analyst", 26 | goal="Provide insights about {company} through market analysis", 27 | verbose=True, 28 | memory=True, 29 | backstory=("""You are a Market Research Analyst conducting research on {company}. 30 | Your main role is to gather and analyze market data to understand market trends, consumer behavior, and competitive dynamics. 31 | Currently, you are working on a project to assess the market potential for {company} and analyze the competitive landscape."""), 32 | tools=[tool], 33 | llm=llm, 34 | #max_rpm=15, 35 | allow_delegation=True) 36 | 37 | #Financial analyst agent 38 | financial_analyst= Agent( 39 | role="Financial Analyst", 40 | goal="Provide comprehensive financial insights about {company}", 41 | verbose=True, 42 | memory=True, 43 | backstory=("""You are a Financial Analyst conducting research on {company}. 44 | Your primary responsibility is to analyze financial data and provide insights 45 | that support strategic decision-making. 46 | Currently, you are working on evaluating {company}'s quarterly performance and preparing financial forecasts for the upcoming year."""), 47 | tools=[tool], 48 | llm=llm, 49 | #max_rpm=15, 50 | allow_delegation=True) 51 | 52 | #Reporting analyst age 53 | reporting_analyst= Agent( 54 | role="Reporting Analyst", 55 | goal="Create sophisticated reports based on the findings from financial and market research analysts about {company}", 56 | verbose=True, 57 | memory=True, 58 | backstory=("""You are a Report Analyst working on research for {company}. 59 | Your primary responsibility is to compile and synthesize data from the Financial Analyst and Market Research Analyst into 60 | comprehensive and sophisticated reports. These reports are used to support strategic business decisions and communicate findings 61 | to stakeholders.Currently, you are working on a detailed report that combines financial performance analysis with market trends 62 | to provide a holistic view of {company}'s current standing and future prospects."""), 63 | tools=[tool], 64 | llm=llm, 65 | #max_rpm=15, 66 | allow_delegation=False) 67 | -------------------------------------------------------------------------------- /app.py: -------------------------------------------------------------------------------- 1 | import streamlit as st 2 | import re 3 | import sys 4 | from crewai import Crew,Process 5 | import os 6 | from agents import reporting_analyst,market_research_analyst,financial_analyst 7 | from tasks import reporting_analysis,market_analysis,financial_analysis 8 | 9 | # Used to stream sys output on the streamlit frontend 10 | class StreamToContainer: 11 | def __init__(self, container): 12 | self.container = container 13 | self.buffer = [] 14 | self.colors = ['red', 'green', 'blue', 'orange'] 15 | self.color_index = 0 16 | 17 | def write(self, data): 18 | # Filter out ANSI escape codes using a regular expression 19 | cleaned_data = re.sub(r'\x1B\[[0-9;]*[mK]', '', data) 20 | 21 | # Check if the data contains 'task' information 22 | task_match_object = re.search(r'\"task\"\s*:\s*\"(.*?)\"', cleaned_data, re.IGNORECASE) 23 | task_match_input = re.search(r'task\s*:\s*([^\n]*)', cleaned_data, re.IGNORECASE) 24 | task_value = None 25 | if task_match_object: 26 | task_value = task_match_object.group(1) 27 | elif task_match_input: 28 | task_value = task_match_input.group(1).strip() 29 | 30 | # Check if the text contains the specified phrase and apply color 31 | if "Entering new CrewAgentExecutor chain" in cleaned_data: 32 | # Apply different color and switch color index 33 | self.color_index = (self.color_index + 1) % len(self.colors) # Increment color index and wrap around if necessary 34 | 35 | cleaned_data = cleaned_data.replace("Entering new CrewAgentExecutor chain", f":{self.colors[self.color_index]}[Entering new CrewAgentExecutor chain]") 36 | 37 | if "Financial Analyst" in cleaned_data: 38 | cleaned_data = cleaned_data.replace("Financial Analyst", f":{self.colors[self.color_index]}[Financial Analyst]") 39 | if "Market Research Analyst" in cleaned_data: 40 | cleaned_data = cleaned_data.replace("Market Research Analyst", f":{self.colors[self.color_index]}[Market Research Analyst]") 41 | if "Reporting Analyst" in cleaned_data: 42 | cleaned_data = cleaned_data.replace("Reporting Analyst", f":{self.colors[self.color_index]}[Reporting Analyst]") 43 | if "Finished chain." in cleaned_data: 44 | cleaned_data = cleaned_data.replace("Finished chain.", f":{self.colors[self.color_index]}[Finished chain.]") 45 | 46 | self.buffer.append(cleaned_data) 47 | if "\n" in data: 48 | self.container.markdown(''.join(self.buffer) , unsafe_allow_html=True) 49 | self.buffer = [] 50 | 51 | 52 | 53 | 54 | st.header("Financial & Market Research Multi-Agent") 55 | st.subheader("Generate a Financial and Market Research Analysis Report!",divider="rainbow",anchor=False) 56 | 57 | with st.form("form"): 58 | company=st.text_input("Enter the name of the Company",key="company") 59 | submitted=st.form_submit_button("Submit") 60 | 61 | 62 | 63 | if submitted: 64 | with st.status("🤖 **Agents at work...**",expanded=True,state="running") as status: 65 | with st.container(height=300): 66 | sys.stdout = StreamToContainer(st) 67 | #Defining the crew comprising of different agents 68 | crew = Crew( 69 | agents=[financial_analyst, market_research_analyst, reporting_analyst], 70 | tasks=[financial_analysis,market_analysis,reporting_analysis], 71 | process=Process.sequential, 72 | verbose=2) 73 | result=crew.kickoff(inputs={"company":company}) 74 | 75 | 76 | 77 | status.update(label="✅ Your Report is ready",state="complete", expanded=False) 78 | st.subheader("Financial and Market Research Report is ready!", anchor=False, divider="rainbow") 79 | st.markdown(result) 80 | 81 | 82 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | load_dotenv 2 | streamlit 3 | crewai 4 | langchain_google_genai 5 | langchain_openai 6 | -------------------------------------------------------------------------------- /tasks.py: -------------------------------------------------------------------------------- 1 | from crewai import Task 2 | from tools import tool 3 | from agents import financial_analyst,market_research_analyst,reporting_analyst 4 | 5 | #3 Tasks would be carried out by different agents, namely Finacial analysis, Market analysis, Report writing 6 | #Financial Analysis 7 | financial_analysis=Task( 8 | description="Analyze the financial performance of {company}", 9 | expected_output="A detailed financial report including key financial ratios, trends, and forecasts", 10 | tools=[tool], 11 | agent=financial_analyst, 12 | 13 | ) 14 | 15 | #Market Analysis 16 | market_analysis=Task( 17 | description="Analyze market trends and competitive landscape for {company}", 18 | expected_output="A comprehensive market research report detailing market trends, consumer behavior, and competitive analysis", 19 | tools=[tool], 20 | agent=market_research_analyst, 21 | 22 | ) 23 | 24 | #Report Wriring 25 | reporting_analysis= Task( 26 | description="Compile and synthesize data from financial and market research analysts into a comprehensive report", 27 | expected_output="A detailed 2 page report that combines financial performance analysis with market trends and competitive analysis for {company}, all important findings should be highlighted", 28 | tools=[tool], 29 | agent=reporting_analyst, 30 | async_execution=False, 31 | 32 | 33 | ) -------------------------------------------------------------------------------- /tools.py: -------------------------------------------------------------------------------- 1 | from dotenv import load_dotenv 2 | from crewai_tools import SerperDevTool 3 | import os 4 | load_dotenv() 5 | 6 | 7 | os.environ["SERPER_API_KEY"]=os.environ.get("SERPER_API_KEY") 8 | 9 | #Tool for searching on Google 10 | tool=SerperDevTool() --------------------------------------------------------------------------------