import os from crewai import Agent, Task, Crew, Process from langchain.tools import Tool # Assuming DuckDuckGoSearchRun or equivalent tool is available import gradio as gr # Assuming WebSearchTools and ChatGoogleGenerativeAI are properly defined and available from WebScape_TOOL import WebSearchTools ################################## - GOOGLE LLM - ################################## from langchain_google_genai import ChatGoogleGenerativeAI # Set up API keys and environment variables api_gemini = 'AIzaSyB4feCeVxvjfd6a6L1jtaV_NHUMSh0MGQk' # Replace with your actual API key os.environ["api_gemini"] = api_gemini # Define the Large Language Model (LLM) llm = ChatGoogleGenerativeAI(model="gemini-pro", verbose=True, temperature=0.1, google_api_key=api_gemini) from langchain.tools import DuckDuckGoSearchRun duckduckgo_search_tool = DuckDuckGoSearchRun() from WebScape_TOOL import WebSearchTools search = WebSearchTools() process = WebSearchTools().process_search_results def create_crewai_crypto_setup(crypto_symbol): # Main Research Agent for technical and market analysis research_agent = Agent( role="Crypto Analysis Expert", goal=f"Perform in-depth analysis on cryptocurrency realted queries, focusing on market outlook, investment strategies, technical/trade signals, and risks.", backstory="Expert in technical analysis, market sentiment, and investment strategy for cryptocurrencies.", verbose=True, allow_delegation=True, tools=[duckduckgo_search_tool], llm=llm, ) research_agent2 = Agent( role="Crypto Analysis Expert", goal=f"""Using the websearchtools perform in-depth research for the cryptocurrency - {crypto_symbol}, focusing on market outlook, investment strategies, technical/trade signals, etc NOTE: Use the Search tool to search and the process tool to scape the url for additonal data, every serch much be followed by a process (webscrape) """, backstory="Expert in technical analysis, market sentiment, and investment strategy for cryptocurrencies.", verbose=True, allow_delegation=False, llm=llm, ) # Task 1: Market Outlook market_data_t0 = Task( description=f"""Search and gather market data and metrics for cryptocurrency - {crypto_symbol} - Only focus on the crypto name and symbol. focus on 2024 and beyond price trends, including timeline of price targets, key price points, buy/sell/hold levels, techincal triggers and metrics, price action, and short, medium, long term predictions along with any other relavant information, metrics and or datapoints.""", expected_output="Group similar data into sections, with information and data metrics presented in a clear and concise manner", tools=[search.pricetargets_search, search.forecast_search, search.technicalsignals_search, process], agent=research_agent2, ) # Task 3: Technical/Trade Signals technical_signals_t3 = Task( description=f""""Research and perform technical analysis on cryptocurrency - {crypto_symbol}, identify recent trade and techincal signals, report over various timeframes, trend type (Bullish, neutral, bearish), and type of indicator like moving averages, RSI, MACD, or other related signars if present during search. note - Use only the crypto symbol to perfom your search""", expected_output="Information in list with summary grouped if possible", tools=[search.technicalsignals_search, process], agent=research_agent, ) ### Gather information and structure it? or not ? #### DEFINE What sections we need in the report for t3 Summary_t3 = Task( description=f""""Create a report based on the request {crypto_symbol} (Focus on talioring the info,metrics, and metrics that are relavant to the query. You have access to all the information you need and can delegate research if needed""", expected_output="Report based on query with summary followed by sections with similar datapoints grouped including relavant data and metrics. The report should be organized, easy to read, clear and concise", agent=research_agent, ) # Crew setup for processing the tasks sequentially crypto_crew = Crew( agents=[research_agent, research_agent2], tasks=[market_data_t0,Summary_t3], verbose=2, process=Process.sequential, ) crew_result = crypto_crew.kickoff() return crew_result # Gradio Interface def run_crewai_app(crypto_symbol): crew_result = create_crewai_crypto_setup(crypto_symbol) return crew_result iface = gr.Interface( fn=run_crewai_app, inputs="text", outputs="text", title="CrewAI Trade Analysis", description="Enter a Cryptocurrency Ticker + (optional) Techincal/trading signals, price predictions, price targets, buy/sell/hold prices." ) iface.launch()