menikev commited on
Commit
8afb178
·
verified ·
1 Parent(s): 61bc418

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +21 -11
main.py CHANGED
@@ -38,16 +38,25 @@ class CryptoCrew:
38
  )
39
 
40
  result = crew.kickoff()
41
-
 
42
  parsed_result = self.parse_result(result)
43
-
44
  return parsed_result
45
 
46
  def parse_result(self, result):
 
 
 
 
 
 
 
 
47
 
48
- result_text = result.content
49
  parsed = {
50
- "summary": result,
51
  "sentiment": {
52
  "overall": "Neutral",
53
  "social_media": "Neutral",
@@ -55,17 +64,18 @@ class CryptoCrew:
55
  "community": "Neutral"
56
  }
57
  }
58
-
59
- if "sentiment score" in result.lower():
60
- sentiment_section = result.split("sentiment score")[1].split("\n")[0]
 
61
  try:
62
  sentiment_score = float(sentiment_section.strip())
63
  if sentiment_score > 0.5:
64
  parsed["sentiment"]["overall"] = "Positive"
65
  elif sentiment_score < -0.5:
66
  parsed["sentiment"]["overall"] = "Negative"
67
- except:
68
- pass
69
 
70
  return parsed
71
 
@@ -76,10 +86,10 @@ if __name__ == "__main__":
76
  dedent("""
77
  What is the cryptocurrency you want to analyze?
78
  """))
79
-
80
  crypto_crew = CryptoCrew(crypto)
81
  result = crypto_crew.run()
82
  print("\n\n########################")
83
  print("## Here is the Report")
84
  print("########################\n")
85
- print(json.dumps(result, indent=2))
 
38
  )
39
 
40
  result = crew.kickoff()
41
+
42
+ # Attempt to parse the result based on its actual structure
43
  parsed_result = self.parse_result(result)
44
+
45
  return parsed_result
46
 
47
  def parse_result(self, result):
48
+ # Attempt to extract a text summary from the result
49
+ # Here, assume result has a method or attribute to get text (like result.get_text(), result.summary, etc.)
50
+ # Replace 'result.get_summary()' with the correct method/attribute after inspecting the result structure
51
+ try:
52
+ result_text = result.get_summary() # Hypothetical method; replace with actual method/attribute
53
+ except AttributeError:
54
+ # If the method or attribute doesn't exist, fall back to another way
55
+ result_text = str(result) # Convert to string if necessary
56
 
57
+ # Initialize the parsed result structure
58
  parsed = {
59
+ "summary": result_text,
60
  "sentiment": {
61
  "overall": "Neutral",
62
  "social_media": "Neutral",
 
64
  "community": "Neutral"
65
  }
66
  }
67
+
68
+ # Perform sentiment extraction on the result_text
69
+ if "sentiment score" in result_text.lower():
70
+ sentiment_section = result_text.split("sentiment score")[1].split("\n")[0]
71
  try:
72
  sentiment_score = float(sentiment_section.strip())
73
  if sentiment_score > 0.5:
74
  parsed["sentiment"]["overall"] = "Positive"
75
  elif sentiment_score < -0.5:
76
  parsed["sentiment"]["overall"] = "Negative"
77
+ except ValueError:
78
+ pass # Handle the case where conversion to float fails
79
 
80
  return parsed
81
 
 
86
  dedent("""
87
  What is the cryptocurrency you want to analyze?
88
  """))
89
+
90
  crypto_crew = CryptoCrew(crypto)
91
  result = crypto_crew.run()
92
  print("\n\n########################")
93
  print("## Here is the Report")
94
  print("########################\n")
95
+ print(json.dumps(result, indent=2))