CryptoScoutv1 commited on
Commit
2c19cee
·
verified ·
1 Parent(s): fd8ce50

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +83 -69
app.py CHANGED
@@ -1,94 +1,108 @@
1
  import os
2
  from crewai import Agent, Task, Crew, Process
3
- from langchain.tools import DuckDuckGoSearchRun
4
-
5
- from langchain.agents import load_tools
6
- from langchain_google_genai import ChatGoogleGenerativeAI
7
-
8
  import gradio as gr
9
 
10
- api_gemini = os.environ["api_gemini"]
 
11
 
12
- # Function to run the Crew AI logic
13
- def run_crew_ai(query):
14
- # Initialize the ChatGoogleGenerativeAI model with verbose set to False
15
- llm2 = ChatGoogleGenerativeAI(
16
- model="gemini-pro", verbose=False, temperature=0.1, google_api_key=api_gemini
17
- )
 
18
 
19
- # Initialize tools
20
- search_tool = DuckDuckGoSearchRun()
21
- human_tools = load_tools(["human"]) ## Agent can ask for human input if they need more details
22
 
23
- # Define Agents with verbose set to False and backstories
24
- researcher = Agent(
25
- role='Researcher',
26
- goal='Identify new and relevant cryptocurrency based on user criteria using the internet tool',
27
- backstory='As a Researcher, I am skilled in navigating the vast ocean of online information to discover emerging and promising cryptocurrencies..',
28
- tools=[search_tool],
29
- verbose=False,
30
- allow_delegation=False,
31
- llm=llm2
32
- )
33
 
34
- info_gatherer = Agent(
35
- role='Information Gatherer',
36
- goal='Collect detailed information about the identified cryptocurrency using the search tool, Structure the query in your search to find the needed information and keep searching.',
37
- backstory='My role as an Information Gatherer is to meticulously compile all relevant data about cryptocurrencies to aid in informed decision-making.',
38
- tools=[search_tool],
39
- verbose=False,
40
- allow_delegation=False,
41
- llm=llm2
 
 
 
 
 
 
 
 
 
 
42
  )
43
-
44
- formatter = Agent(
45
- role='Formatter',
46
- goal='Structure all gathered information into a clear, concise format, if information is missing from the final format I will pass the task back to the info_gather agent.',
47
- backstory='As a Formatter, I excel in organizing complex information into a structured and easily understandable format for the end-user.',
48
- verbose=False,
 
 
49
  allow_delegation=False,
50
- llm=llm2
51
  )
52
 
53
- # Define Tasks
54
- research_task = Task(
55
- description=f'Search the internet for a cryptocurrency that matches the user\'s prompt. Here is the prompt: "{query}"',
56
- agent=researcher
 
 
 
 
 
 
 
57
  )
58
 
59
- gather_task = Task(
60
- description='Gather all relevant information about the identified cryptocurrency including a summary, todays price, todays market capilization, offical URL.',
61
- agent=info_gatherer
 
 
 
 
 
 
62
  )
63
-
64
- format_task = Task(
65
- description='Structure the gathered information in a list structure with all the relevant details neat and user friendly',
66
- agent=formatter
 
 
 
 
 
67
  )
68
 
69
- # Define and run the Crew
70
- crew = Crew(
71
- agents=[researcher, info_gatherer, formatter],
72
- tasks=[research_task, gather_task, format_task],
 
73
  process=Process.sequential,
74
- verbose=0 # Minimize verbose output
75
  )
76
- result = crew.kickoff()
77
 
78
- return result
79
 
80
- # Gradio Interface Setup
81
- def gradio_interface(query):
82
- return run_crew_ai(query)
 
83
 
84
- # Create a Gradio interface with an input textbox and output text
85
- interface = gr.Interface(
86
- fn=gradio_interface,
87
- inputs="text",
88
  outputs="text",
89
- title="Crew AI Cryptocurrency Researcher",
90
- description="Enter a query to research cryptocurrencies using Crew AI."
91
  )
92
 
93
- # Launch the Gradio interface
94
- interface.launch()
 
1
  import os
2
  from crewai import Agent, Task, Crew, Process
3
+ from langchain.tools import Tool # Assuming DuckDuckGoSearchRun or equivalent tool is available
 
 
 
 
4
  import gradio as gr
5
 
6
+ # Assuming WebSearchTools and ChatGoogleGenerativeAI are properly defined and available
7
+ from WebScape_TOOL import WebSearchTools
8
 
9
+ ################################## - GOOGLE LLM - ##################################
10
+ from langchain_google_genai import ChatGoogleGenerativeAI
11
+ # Set up API keys and environment variables
12
+ api_gemini = 'AIzaSyB4feCeVxvjfd6a6L1jtaV_NHUMSh0MGQk' # Replace with your actual API key
13
+ os.environ["api_gemini"] = api_gemini
14
+ # Define the Large Language Model (LLM)
15
+ llm = ChatGoogleGenerativeAI(model="gemini-pro", verbose=True, temperature=0.1, google_api_key=api_gemini)
16
 
 
 
 
17
 
 
 
 
 
 
 
 
 
 
 
18
 
19
+ from langchain.tools import DuckDuckGoSearchRun
20
+ duckduckgo_search_tool = DuckDuckGoSearchRun()
21
+
22
+ from WebScape_TOOL import WebSearchTools
23
+
24
+ search = WebSearchTools()
25
+ process = WebSearchTools().process_search_results
26
+
27
+ def create_crewai_crypto_setup(crypto_symbol):
28
+ # Main Research Agent for technical and market analysis
29
+ research_agent = Agent(
30
+ role="Crypto Analysis Expert",
31
+ goal=f"Perform in-depth analysis on cryptocurrency realted queries, focusing on market outlook, investment strategies, technical/trade signals, and risks.",
32
+ backstory="Expert in technical analysis, market sentiment, and investment strategy for cryptocurrencies.",
33
+ verbose=True,
34
+ allow_delegation=True,
35
+ tools=[duckduckgo_search_tool],
36
+ llm=llm,
37
  )
38
+ research_agent2 = Agent(
39
+ role="Crypto Analysis Expert",
40
+ goal=f"""Using the websearchtools perform in-depth research for the cryptocurrency - {crypto_symbol},
41
+ focusing on market outlook, investment strategies, technical/trade signals, etc
42
+ 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)
43
+ """,
44
+ backstory="Expert in technical analysis, market sentiment, and investment strategy for cryptocurrencies.",
45
+ verbose=True,
46
  allow_delegation=False,
47
+ llm=llm,
48
  )
49
 
50
+ # Task 1: Market Outlook
51
+ market_data_t0 = Task(
52
+ description=f"""Search and gather market data and metrics for cryptocurrency - {crypto_symbol} - Only focus on the crypto name and symbol.
53
+ focus on 2024 and beyond price trends, including timeline of price targets, key price points, buy/sell/hold levels,
54
+ techincal triggers and metrics, price action, and short, medium, long term predictions along with any other relavant information, metrics and or datapoints.""",
55
+ expected_output="Group similar data into sections, with information and data metrics presented in a clear and concise manner",
56
+ tools=[search.pricetargets_search,
57
+ search.forecast_search,
58
+ search.technicalsignals_search,
59
+ process],
60
+ agent=research_agent2,
61
  )
62
 
63
+ # Task 3: Technical/Trade Signals
64
+ technical_signals_t3 = Task(
65
+ description=f""""Research and perform technical analysis on cryptocurrency - {crypto_symbol},
66
+ identify recent trade and techincal signals, report over various timeframes, trend type (Bullish, neutral, bearish),
67
+ and type of indicator like moving averages, RSI, MACD, or other related signars if present during search.
68
+ note - Use only the crypto symbol to perfom your search""",
69
+ expected_output="Information in list with summary grouped if possible",
70
+ tools=[search.technicalsignals_search, process],
71
+ agent=research_agent,
72
  )
73
+
74
+ ### Gather information and structure it? or not ?
75
+ #### DEFINE What sections we need in the report for t3
76
+
77
+ Summary_t3 = Task(
78
+ description=f""""Create a report based on the request {crypto_symbol} (Focus on talioring the info,metrics, and metrics
79
+ that are relavant to the query. You have access to all the information you need and can delegate research if needed""",
80
+ 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",
81
+ agent=research_agent,
82
  )
83
 
84
+ # Crew setup for processing the tasks sequentially
85
+ crypto_crew = Crew(
86
+ agents=[research_agent, research_agent2],
87
+ tasks=[market_data_t0,Summary_t3],
88
+ verbose=2,
89
  process=Process.sequential,
 
90
  )
91
+ crew_result = crypto_crew.kickoff()
92
 
93
+ return crew_result
94
 
95
+ # Gradio Interface
96
+ def run_crewai_app(crypto_symbol):
97
+ crew_result = create_crewai_crypto_setup(crypto_symbol)
98
+ return crew_result
99
 
100
+ iface = gr.Interface(
101
+ fn=run_crewai_app,
102
+ inputs="text",
 
103
  outputs="text",
104
+ title="CrewAI Trade Analysis",
105
+ description="Enter a Cryptocurrency Ticker + (optional) Techincal/trading signals, price predictions, price targets, buy/sell/hold prices."
106
  )
107
 
108
+ iface.launch()