Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
@@ -1,7 +1,7 @@
|
|
|
|
1 |
from crewai import Crew
|
2 |
from textwrap import dedent
|
3 |
import json
|
4 |
-
|
5 |
from crypto_analysis_agents import CryptoAnalysisAgents
|
6 |
from crypto__analysis_tasks import CryptoAnalysisTasks
|
7 |
|
@@ -9,7 +9,7 @@ class CryptoCrew:
|
|
9 |
def __init__(self, crypto):
|
10 |
self.crypto = crypto
|
11 |
|
12 |
-
def run(self):
|
13 |
agents = CryptoAnalysisAgents()
|
14 |
tasks = CryptoAnalysisTasks()
|
15 |
|
@@ -35,63 +35,30 @@ class CryptoCrew:
|
|
35 |
recommend_task
|
36 |
],
|
37 |
verbose=True,
|
38 |
-
iteration_limit=
|
39 |
-
time_limit=
|
40 |
)
|
41 |
|
42 |
-
|
|
|
|
|
|
|
43 |
|
44 |
-
# Attempt to parse the result based on its actual structure
|
45 |
parsed_result = self.parse_result(result)
|
46 |
-
|
47 |
return parsed_result
|
48 |
|
49 |
def parse_result(self, result):
|
50 |
-
#
|
51 |
-
# Here, assume result has a method or attribute to get text (like result.get_text(), result.summary, etc.)
|
52 |
-
# Replace 'result.get_summary()' with the correct method/attribute after inspecting the result structure
|
53 |
-
try:
|
54 |
-
result_text = result.get_summary() # Hypothetical method; replace with actual method/attribute
|
55 |
-
except AttributeError:
|
56 |
-
# If the method or attribute doesn't exist, fall back to another way
|
57 |
-
result_text = str(result) # Convert to string if necessary
|
58 |
-
|
59 |
-
# Initialize the parsed result structure
|
60 |
-
parsed = {
|
61 |
-
"summary": result_text,
|
62 |
-
"sentiment": {
|
63 |
-
"overall": "Neutral",
|
64 |
-
"social_media": "Neutral",
|
65 |
-
"news": "Neutral",
|
66 |
-
"community": "Neutral"
|
67 |
-
}
|
68 |
-
}
|
69 |
-
|
70 |
-
# Perform sentiment extraction on the result_text
|
71 |
-
if "sentiment score" in result_text.lower():
|
72 |
-
sentiment_section = result_text.split("sentiment score")[1].split("\n")[0]
|
73 |
-
try:
|
74 |
-
sentiment_score = float(sentiment_section.strip())
|
75 |
-
if sentiment_score > 0.5:
|
76 |
-
parsed["sentiment"]["overall"] = "Positive"
|
77 |
-
elif sentiment_score < -0.5:
|
78 |
-
parsed["sentiment"]["overall"] = "Negative"
|
79 |
-
except ValueError:
|
80 |
-
pass # Handle the case where conversion to float fails
|
81 |
-
|
82 |
-
return parsed
|
83 |
|
84 |
if __name__ == "__main__":
|
85 |
print("## Welcome to Crypto Analysis Crew")
|
86 |
print('-------------------------------')
|
87 |
-
crypto = input(
|
88 |
-
|
89 |
-
|
90 |
-
"""))
|
91 |
-
|
92 |
crypto_crew = CryptoCrew(crypto)
|
93 |
-
result = crypto_crew.run()
|
94 |
print("\n\n########################")
|
95 |
print("## Here is the Report")
|
96 |
print("########################\n")
|
97 |
-
print(json.dumps(result, indent=2))
|
|
|
1 |
+
import asyncio
|
2 |
from crewai import Crew
|
3 |
from textwrap import dedent
|
4 |
import json
|
|
|
5 |
from crypto_analysis_agents import CryptoAnalysisAgents
|
6 |
from crypto__analysis_tasks import CryptoAnalysisTasks
|
7 |
|
|
|
9 |
def __init__(self, crypto):
|
10 |
self.crypto = crypto
|
11 |
|
12 |
+
async def run(self):
|
13 |
agents = CryptoAnalysisAgents()
|
14 |
tasks = CryptoAnalysisTasks()
|
15 |
|
|
|
35 |
recommend_task
|
36 |
],
|
37 |
verbose=True,
|
38 |
+
iteration_limit=300,
|
39 |
+
time_limit=600
|
40 |
)
|
41 |
|
42 |
+
try:
|
43 |
+
result = await asyncio.wait_for(crew.kickoff(), timeout=600)
|
44 |
+
except asyncio.TimeoutError:
|
45 |
+
return {"summary": "Analysis timed out. Please try again with a simpler query or increased time limit."}
|
46 |
|
|
|
47 |
parsed_result = self.parse_result(result)
|
|
|
48 |
return parsed_result
|
49 |
|
50 |
def parse_result(self, result):
|
51 |
+
# ... (rest of the parse_result method remains the same)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
|
53 |
if __name__ == "__main__":
|
54 |
print("## Welcome to Crypto Analysis Crew")
|
55 |
print('-------------------------------')
|
56 |
+
crypto = input(dedent("""
|
57 |
+
What is the cryptocurrency you want to analyze?
|
58 |
+
"""))
|
|
|
|
|
59 |
crypto_crew = CryptoCrew(crypto)
|
60 |
+
result = asyncio.run(crypto_crew.run())
|
61 |
print("\n\n########################")
|
62 |
print("## Here is the Report")
|
63 |
print("########################\n")
|
64 |
+
print(json.dumps(result, indent=2))
|