Create appv2.py
Browse files
appv2.py
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 # Custom class for web search and BeautifulSoup processing
|
| 8 |
+
|
| 9 |
+
from langchain_google_genai import ChatGoogleGenerativeAI
|
| 10 |
+
|
| 11 |
+
# Set up API keys and environment variables
|
| 12 |
+
api_gemini = 'AIzaSyDkIoeAfuJoHCN3-Db-gojZd2Kzghunr3U'
|
| 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 |
+
from langchain.tools import DuckDuckGoSearchRun
|
| 19 |
+
duckduckgo_search_tool = DuckDuckGoSearchRun()
|
| 20 |
+
|
| 21 |
+
def create_crewai_crypto_setup(crypto_symbol):
|
| 22 |
+
# Main Research Agent for technical and market analysis
|
| 23 |
+
research_agent = Agent(
|
| 24 |
+
role="Crypto Analysis Expert",
|
| 25 |
+
goal=f"Perform in-depth analysis on cryptocurrency - {crypto_symbol}, focusing on market outlook, investment strategies, technical/trade signals, and risks.",
|
| 26 |
+
backstory="Expert in technical analysis, market sentiment, and investment strategy for cryptocurrencies.",
|
| 27 |
+
verbose=True,
|
| 28 |
+
allow_delegation=False,
|
| 29 |
+
tools=[duckduckgo_search_tool],
|
| 30 |
+
llm=llm,
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
# Task 1: Market Outlook
|
| 34 |
+
market_outlook_t1 = Task(
|
| 35 |
+
description=f"Research and report on cryptocurrency - {crypto_symbol} historical price trends, including timeline of price targets, price action, and short, medium, long term predictions.",
|
| 36 |
+
expected_output="Summary of important information and actionale insights. Final ouput strictly 500 chars. or less",
|
| 37 |
+
tools=[WebSearchTools().forecast_search, WebSearchTools().process_search_results],
|
| 38 |
+
agent=research_agent,
|
| 39 |
+
)
|
| 40 |
+
|
| 41 |
+
# Task 2: Investment Strategies
|
| 42 |
+
investment_strategies_t2 = Task(
|
| 43 |
+
description=f"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.",
|
| 44 |
+
expected_output="Summary of important information and data. Final Ouput strictly 500 chars. or less",
|
| 45 |
+
tools=[WebSearchTools().pricetargets_search, WebSearchTools().process_search_results, duckduckgo_search_tool],
|
| 46 |
+
agent=research_agent,
|
| 47 |
+
)
|
| 48 |
+
|
| 49 |
+
# Task 3: Technical/Trade Signals
|
| 50 |
+
technical_signals_t3 = Task(
|
| 51 |
+
description=f"Research and perform technical analysis on cryptocurrency - {crypto_symbol}, identify trade and techincal signals and or indicators for bullish or bearish trends.",
|
| 52 |
+
expected_output="Summary of information. Final Ouput strictly 500 chars. or less",
|
| 53 |
+
tools=[WebSearchTools().technicalsignals_search, WebSearchTools().process_search_results],
|
| 54 |
+
agent=research_agent,
|
| 55 |
+
)
|
| 56 |
+
|
| 57 |
+
# Task 4: Risks
|
| 58 |
+
risks_t4 = Task(
|
| 59 |
+
description=f"Research recent sentiment, news, volatility and other risks associcated with cryptocurrency - {crypto_symbol}.",
|
| 60 |
+
expected_output="Summary of identified risks. Final Ouput strictly 500 chars. or less",
|
| 61 |
+
tools=[duckduckgo_search_tool],
|
| 62 |
+
agent=research_agent,
|
| 63 |
+
)
|
| 64 |
+
|
| 65 |
+
# Crew setup for processing the tasks sequentially
|
| 66 |
+
crypto_crew = Crew(
|
| 67 |
+
agents=[research_agent],
|
| 68 |
+
tasks=[market_outlook_t1, investment_strategies_t2, technical_signals_t3, risks_t4],
|
| 69 |
+
verbose=2,
|
| 70 |
+
process=Process.sequential,
|
| 71 |
+
)
|
| 72 |
+
crew_result = crypto_crew.kickoff()
|
| 73 |
+
############################### - CREW - ###############################
|
| 74 |
+
### FINAL REPORT - ## Mapping task results to section titles for output
|
| 75 |
+
section_titles = {
|
| 76 |
+
"Market Outlook": market_outlook_t1.output.result,
|
| 77 |
+
"Invesment Report": investment_strategies_t2.output.result,
|
| 78 |
+
"Technical Analysis": technical_signals_t3.output.result,
|
| 79 |
+
"Risk Analysis": risks_t4.output.result,
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
return section_titles
|
| 83 |
+
|
| 84 |
+
# Adjusted Gradio interface function to include section titles
|
| 85 |
+
def run_crewai_app(coin_name):
|
| 86 |
+
results = create_crewai_crypto_setup(coin_name)
|
| 87 |
+
output = '\n\n'.join([f"{title}:\n{result}" for title, result in results.items()])
|
| 88 |
+
return output
|
| 89 |
+
|
| 90 |
+
iface = gr.Interface(
|
| 91 |
+
fn=run_crewai_app,
|
| 92 |
+
inputs="text",
|
| 93 |
+
outputs="text",
|
| 94 |
+
title="CryptoScout - CrewAI - Cryptocurrency Report Builder",
|
| 95 |
+
description="Enter a cryptocurrency name to analyze and generate a comprehensive investment report."
|
| 96 |
+
)
|
| 97 |
+
|
| 98 |
+
iface.launch()
|