Spaces:
Running
Running
Update main.py
Browse files
main.py
CHANGED
|
@@ -9,6 +9,10 @@ class CryptoCrew:
|
|
| 9 |
def __init__(self, crypto):
|
| 10 |
self.crypto = crypto
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
async def run_async(self):
|
| 13 |
agents = CryptoAnalysisAgents()
|
| 14 |
tasks = CryptoAnalysisTasks()
|
|
@@ -40,48 +44,18 @@ class CryptoCrew:
|
|
| 40 |
)
|
| 41 |
|
| 42 |
try:
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
|
|
|
| 46 |
|
| 47 |
parsed_result = self.parse_result(result)
|
| 48 |
return parsed_result
|
| 49 |
|
| 50 |
-
def run(self):
|
| 51 |
-
return asyncio.run(self.run_async())
|
| 52 |
-
|
| 53 |
def parse_result(self, result):
|
| 54 |
-
#
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
except AttributeError:
|
| 58 |
-
# If the method or attribute doesn't exist, fall back to another way
|
| 59 |
-
result_text = str(result) # Convert to string if necessary
|
| 60 |
-
|
| 61 |
-
# Initialize the parsed result structure
|
| 62 |
-
parsed = {
|
| 63 |
-
"summary": result_text,
|
| 64 |
-
"sentiment": {
|
| 65 |
-
"overall": "Neutral",
|
| 66 |
-
"social_media": "Neutral",
|
| 67 |
-
"news": "Neutral",
|
| 68 |
-
"community": "Neutral"
|
| 69 |
-
}
|
| 70 |
-
}
|
| 71 |
-
|
| 72 |
-
# Perform sentiment extraction on the result_text
|
| 73 |
-
if "sentiment score" in result_text.lower():
|
| 74 |
-
sentiment_section = result_text.split("sentiment score")[1].split("\n")[0]
|
| 75 |
-
try:
|
| 76 |
-
sentiment_score = float(sentiment_section.strip())
|
| 77 |
-
if sentiment_score > 0.5:
|
| 78 |
-
parsed["sentiment"]["overall"] = "Positive"
|
| 79 |
-
elif sentiment_score < -0.5:
|
| 80 |
-
parsed["sentiment"]["overall"] = "Negative"
|
| 81 |
-
except ValueError:
|
| 82 |
-
pass # Handle the case where conversion to float fails
|
| 83 |
-
|
| 84 |
-
return parsed
|
| 85 |
|
| 86 |
if __name__ == "__main__":
|
| 87 |
print("## Welcome to Crypto Analysis Crew")
|
|
|
|
| 9 |
def __init__(self, crypto):
|
| 10 |
self.crypto = crypto
|
| 11 |
|
| 12 |
+
def run(self):
|
| 13 |
+
# This method can be called from synchronous code
|
| 14 |
+
return asyncio.run(self.run_async())
|
| 15 |
+
|
| 16 |
async def run_async(self):
|
| 17 |
agents = CryptoAnalysisAgents()
|
| 18 |
tasks = CryptoAnalysisTasks()
|
|
|
|
| 44 |
)
|
| 45 |
|
| 46 |
try:
|
| 47 |
+
# Use asyncio.to_thread to run the synchronous crew.kickoff() in a separate thread
|
| 48 |
+
result = await asyncio.to_thread(crew.kickoff)
|
| 49 |
+
except Exception as e:
|
| 50 |
+
return {"summary": f"Analysis failed: {str(e)}. Please try again."}
|
| 51 |
|
| 52 |
parsed_result = self.parse_result(result)
|
| 53 |
return parsed_result
|
| 54 |
|
|
|
|
|
|
|
|
|
|
| 55 |
def parse_result(self, result):
|
| 56 |
+
# Implement your parse_result method here
|
| 57 |
+
# This is a placeholder implementation
|
| 58 |
+
return {"summary": str(result)}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
|
| 60 |
if __name__ == "__main__":
|
| 61 |
print("## Welcome to Crypto Analysis Crew")
|