CryptoScoutv1's picture
Update app.py
a535fe4 verified
from crewai import Agent, Task, Crew, Process
from langchain.tools import Tool
import gradio as gr
################################## - GOOGLE LLM - ##################################
import os
from langchain_google_genai import ChatGoogleGenerativeAI
api_gemini = os.environ["api_gemini"]
# Define the Large Language Model (LLM)
llm = ChatGoogleGenerativeAI(
model="gemini-pro",
verbose=True,
temperature=0.1,
google_api_key=api_gemini)
################################## - GOOGLE LLM - ##################################
from langchain.tools import DuckDuckGoSearchRun
duckduckgo_search_tool = DuckDuckGoSearchRun()
from WebScape_TOOL import WebSearchTools
search = WebSearchTools()
process = WebSearchTools().process_search_results
################################## - CREW and TASKS - ##################################
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 market analysis on cryptocurrency - {crypto_symbol}, focusing on market outlook, investment strategies, technical/trade signals, and risks.
Note: Always use the process tool after the search to get futher data.
""",
backstory="Expert in technical analysis, market sentiment, and investment strategy for cryptocurrencies.",
verbose=True,
allow_delegation=False,
tools=[duckduckgo_search_tool],
llm=llm,
)
# Task 1: Market Outlook
market_outlook_t0 = Task(
description=f"Research cryptocurrency - {crypto_symbol} focus on 2024 and beyond price trends, including timeline of price targets, price action, and short, medium, long term predictions.",
tools=[search.forecast_search, process],
agent=research_agent,
)
# Task 1: Market Outlook
market_outlook_t1 = Task(
description=f"Create a report based on the last task output on cryptocurrency - {crypto_symbol} focus on 2024 and beyond price trends, including timeline of price targets, price action, and short, medium, long term predictions.",
expected_output="Summary of important information and actionale insights focusing on any numbers or metrics. Final ouput strictly equal to or less than 600 chars.",
context=[market_outlook_t0],
agent=research_agent,
)
# Task 2: Investment Strategies - Doesnt use tool most of the time??
investment_strategies_t2 = Task(
description=f"Using the search tools avaliable, develop investment strategies for {crypto_symbol}, including price levels to buy/sell/hold based on current market analysis and or recent support and resistance level.",
expected_output="Summary of important information and data focusing on any numbers or metrics. Final Ouput strictly equal to or less than 550 chars.",
tools=[search.pricetargets_search, process],
agent=research_agent,
)
# 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, Look for daily timeframe, 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="Summary of information highlighting metrics or numbers if present. Final Ouput strictly equal to or less than 600 chars.",
tools=[search.technicalsignals_search, process],
agent=research_agent,
)
# Task 4: Risks
risks_t4 = Task(
description=f"Research recent sentiment, news, volatility and other risks associcated with cryptocurrency - {crypto_symbol}.",
expected_output="Summary of identified risks. Final Ouput strictly 300 chars. or less",
tools=[duckduckgo_search_tool],
agent=research_agent,
)
# Crew setup for processing the tasks sequentially
crypto_crew = Crew(
agents=[research_agent],
tasks=[market_outlook_t0, market_outlook_t1, investment_strategies_t2, technical_signals_t3, risks_t4],
verbose=2,
process=Process.sequential,
)
crew_result = crypto_crew.kickoff()
################################## - CREW and TASKS - ##################################
################################## - REPORT - ##################################
section_titles = {
"Market Outlook": market_outlook_t1.output.result,
"Invesment Report": investment_strategies_t2.output.result,
"Technical Analysis": technical_signals_t3.output.result,
"Risk Analysis": risks_t4.output.result,
}
return section_titles
################################## - REPORT - ##################################
################################## - GRADIO - ##################################
def run_crewai_app(coin_name):
results = create_crewai_crypto_setup(coin_name)
output = '\n\n'.join([f"{title}:\n{result}" for title, result in results.items()])
return output
iface = gr.Interface(
fn=run_crewai_app,
inputs="text",
outputs="text",
title="CryptoScout - CrewAI - Cryptocurrency Trade Advisor",
description="Enter a cryptocurrency name to analyze and generate a comprehensive trade report."
)
iface.launch()
################################## - GRADIO - ##################################