Spaces:
Build error
Build error
Update app.py
Browse files
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 |
-
|
|
|
|
| 11 |
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 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 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
)
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
|
|
|
|
|
|
| 49 |
allow_delegation=False,
|
| 50 |
-
llm=
|
| 51 |
)
|
| 52 |
|
| 53 |
-
#
|
| 54 |
-
|
| 55 |
-
description=f
|
| 56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
)
|
| 58 |
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
)
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
)
|
| 68 |
|
| 69 |
-
#
|
| 70 |
-
|
| 71 |
-
agents=[
|
| 72 |
-
tasks=[
|
|
|
|
| 73 |
process=Process.sequential,
|
| 74 |
-
verbose=0 # Minimize verbose output
|
| 75 |
)
|
| 76 |
-
|
| 77 |
|
| 78 |
-
return
|
| 79 |
|
| 80 |
-
# Gradio Interface
|
| 81 |
-
def
|
| 82 |
-
|
|
|
|
| 83 |
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
inputs="text",
|
| 88 |
outputs="text",
|
| 89 |
-
title="
|
| 90 |
-
description="Enter a
|
| 91 |
)
|
| 92 |
|
| 93 |
-
|
| 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()
|
|
|