Spaces:
Running
Running
Update main.py
Browse files
main.py
CHANGED
|
@@ -1,88 +1,88 @@
|
|
| 1 |
-
from crewai import Crew
|
| 2 |
-
from textwrap import dedent
|
| 3 |
-
import json
|
| 4 |
-
|
| 5 |
-
from crypto_analysis_agents import
|
| 6 |
-
from crypto_analysis_tasks import CryptoAnalysisTasks
|
| 7 |
-
|
| 8 |
-
class CryptoCrew:
|
| 9 |
-
def __init__(self, crypto):
|
| 10 |
-
self.crypto = crypto
|
| 11 |
-
|
| 12 |
-
def run(self):
|
| 13 |
-
agents =
|
| 14 |
-
tasks = CryptoAnalysisTasks()
|
| 15 |
-
|
| 16 |
-
market_analyst_agent = agents.market_analyst()
|
| 17 |
-
technical_analyst_agent = agents.technical_analyst()
|
| 18 |
-
crypto_advisor_agent = agents.crypto_advisor()
|
| 19 |
-
|
| 20 |
-
market_research_task = tasks.market_research(market_analyst_agent, self.crypto)
|
| 21 |
-
technical_analysis_task = tasks.technical_analysis(technical_analyst_agent)
|
| 22 |
-
sentiment_analysis_task = tasks.sentiment_analysis(market_analyst_agent)
|
| 23 |
-
recommend_task = tasks.recommend(crypto_advisor_agent)
|
| 24 |
-
|
| 25 |
-
crew = Crew(
|
| 26 |
-
agents=[
|
| 27 |
-
market_analyst_agent,
|
| 28 |
-
technical_analyst_agent,
|
| 29 |
-
crypto_advisor_agent
|
| 30 |
-
],
|
| 31 |
-
tasks=[
|
| 32 |
-
market_research_task,
|
| 33 |
-
technical_analysis_task,
|
| 34 |
-
sentiment_analysis_task,
|
| 35 |
-
recommend_task
|
| 36 |
-
],
|
| 37 |
-
verbose=True
|
| 38 |
-
)
|
| 39 |
-
|
| 40 |
-
result = crew.kickoff()
|
| 41 |
-
|
| 42 |
-
# Parse the result to extract structured data
|
| 43 |
-
parsed_result = self.parse_result(result)
|
| 44 |
-
|
| 45 |
-
return parsed_result
|
| 46 |
-
|
| 47 |
-
def parse_result(self, result):
|
| 48 |
-
# This is a simple parser. You might need to adjust it based on the actual structure of your result
|
| 49 |
-
parsed = {
|
| 50 |
-
"summary": result,
|
| 51 |
-
"sentiment": {
|
| 52 |
-
"overall": "Neutral",
|
| 53 |
-
"social_media": "Neutral",
|
| 54 |
-
"news": "Neutral",
|
| 55 |
-
"community": "Neutral"
|
| 56 |
-
}
|
| 57 |
-
}
|
| 58 |
-
|
| 59 |
-
# Extract sentiment information
|
| 60 |
-
if "sentiment score" in result.lower():
|
| 61 |
-
sentiment_section = result.split("sentiment score")[1].split("\n")[0]
|
| 62 |
-
try:
|
| 63 |
-
sentiment_score = float(sentiment_section.strip())
|
| 64 |
-
if sentiment_score > 0.5:
|
| 65 |
-
parsed["sentiment"]["overall"] = "Positive"
|
| 66 |
-
elif sentiment_score < -0.5:
|
| 67 |
-
parsed["sentiment"]["overall"] = "Negative"
|
| 68 |
-
except:
|
| 69 |
-
pass
|
| 70 |
-
|
| 71 |
-
# You can add more parsing logic here to extract other structured data
|
| 72 |
-
|
| 73 |
-
return parsed
|
| 74 |
-
|
| 75 |
-
if __name__ == "__main__":
|
| 76 |
-
print("## Welcome to Crypto Analysis Crew")
|
| 77 |
-
print('-------------------------------')
|
| 78 |
-
crypto = input(
|
| 79 |
-
dedent("""
|
| 80 |
-
What is the cryptocurrency you want to analyze?
|
| 81 |
-
"""))
|
| 82 |
-
|
| 83 |
-
crypto_crew = CryptoCrew(crypto)
|
| 84 |
-
result = crypto_crew.run()
|
| 85 |
-
print("\n\n########################")
|
| 86 |
-
print("## Here is the Report")
|
| 87 |
-
print("########################\n")
|
| 88 |
print(json.dumps(result, indent=2))
|
|
|
|
| 1 |
+
from crewai import Crew
|
| 2 |
+
from textwrap import dedent
|
| 3 |
+
import json
|
| 4 |
+
|
| 5 |
+
from crypto_analysis_agents import CryptoAnalysisAgent
|
| 6 |
+
from crypto_analysis_tasks import CryptoAnalysisTasks
|
| 7 |
+
|
| 8 |
+
class CryptoCrew:
|
| 9 |
+
def __init__(self, crypto):
|
| 10 |
+
self.crypto = crypto
|
| 11 |
+
|
| 12 |
+
def run(self):
|
| 13 |
+
agents = CryptoAnalysisAgent()
|
| 14 |
+
tasks = CryptoAnalysisTasks()
|
| 15 |
+
|
| 16 |
+
market_analyst_agent = agents.market_analyst()
|
| 17 |
+
technical_analyst_agent = agents.technical_analyst()
|
| 18 |
+
crypto_advisor_agent = agents.crypto_advisor()
|
| 19 |
+
|
| 20 |
+
market_research_task = tasks.market_research(market_analyst_agent, self.crypto)
|
| 21 |
+
technical_analysis_task = tasks.technical_analysis(technical_analyst_agent)
|
| 22 |
+
sentiment_analysis_task = tasks.sentiment_analysis(market_analyst_agent)
|
| 23 |
+
recommend_task = tasks.recommend(crypto_advisor_agent)
|
| 24 |
+
|
| 25 |
+
crew = Crew(
|
| 26 |
+
agents=[
|
| 27 |
+
market_analyst_agent,
|
| 28 |
+
technical_analyst_agent,
|
| 29 |
+
crypto_advisor_agent
|
| 30 |
+
],
|
| 31 |
+
tasks=[
|
| 32 |
+
market_research_task,
|
| 33 |
+
technical_analysis_task,
|
| 34 |
+
sentiment_analysis_task,
|
| 35 |
+
recommend_task
|
| 36 |
+
],
|
| 37 |
+
verbose=True
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
result = crew.kickoff()
|
| 41 |
+
|
| 42 |
+
# Parse the result to extract structured data
|
| 43 |
+
parsed_result = self.parse_result(result)
|
| 44 |
+
|
| 45 |
+
return parsed_result
|
| 46 |
+
|
| 47 |
+
def parse_result(self, result):
|
| 48 |
+
# This is a simple parser. You might need to adjust it based on the actual structure of your result
|
| 49 |
+
parsed = {
|
| 50 |
+
"summary": result,
|
| 51 |
+
"sentiment": {
|
| 52 |
+
"overall": "Neutral",
|
| 53 |
+
"social_media": "Neutral",
|
| 54 |
+
"news": "Neutral",
|
| 55 |
+
"community": "Neutral"
|
| 56 |
+
}
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
# Extract sentiment information
|
| 60 |
+
if "sentiment score" in result.lower():
|
| 61 |
+
sentiment_section = result.split("sentiment score")[1].split("\n")[0]
|
| 62 |
+
try:
|
| 63 |
+
sentiment_score = float(sentiment_section.strip())
|
| 64 |
+
if sentiment_score > 0.5:
|
| 65 |
+
parsed["sentiment"]["overall"] = "Positive"
|
| 66 |
+
elif sentiment_score < -0.5:
|
| 67 |
+
parsed["sentiment"]["overall"] = "Negative"
|
| 68 |
+
except:
|
| 69 |
+
pass
|
| 70 |
+
|
| 71 |
+
# You can add more parsing logic here to extract other structured data
|
| 72 |
+
|
| 73 |
+
return parsed
|
| 74 |
+
|
| 75 |
+
if __name__ == "__main__":
|
| 76 |
+
print("## Welcome to Crypto Analysis Crew")
|
| 77 |
+
print('-------------------------------')
|
| 78 |
+
crypto = input(
|
| 79 |
+
dedent("""
|
| 80 |
+
What is the cryptocurrency you want to analyze?
|
| 81 |
+
"""))
|
| 82 |
+
|
| 83 |
+
crypto_crew = CryptoCrew(crypto)
|
| 84 |
+
result = crypto_crew.run()
|
| 85 |
+
print("\n\n########################")
|
| 86 |
+
print("## Here is the Report")
|
| 87 |
+
print("########################\n")
|
| 88 |
print(json.dumps(result, indent=2))
|