zerito commited on
Commit
ab28e2c
·
verified ·
1 Parent(s): 633d55c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -7
app.py CHANGED
@@ -51,15 +51,27 @@ def compute_moving_average(prices, window):
51
 
52
  ### 🔹 1. Fetch Latest BTC News ###
53
  @tool
54
- def fetch_btc_news() -> List[Dict[str, str]]:
55
  """
56
- Fetches the latest Bitcoin news from CryptoPanic API.
57
- Returns a list of dictionaries containing 'title' and 'url' of the articles.
 
 
 
 
 
 
58
  """
59
- url = "https://cryptopanic.com/api/v1/posts/?auth_token=ccbeafb47d266a78086f76c3f547546f6b747e88&currencies=BTC"
60
- data = fetch_data(url)
61
- return [{"title": post["title"], "url": post["url"]} for post in data.get("results", [])[:5]]
62
-
 
 
 
 
 
 
63
 
64
  ### 🔹 2. Analyze News Sentiment ###
65
  @tool
 
51
 
52
  ### 🔹 1. Fetch Latest BTC News ###
53
  @tool
54
+ def analyze_btc_news(articles: List[Dict[str, str]]) -> Dict[str, any]:
55
  """
56
+ Analyzes sentiment of Bitcoin news articles using TextBlob.
57
+
58
+ Arguments:
59
+ articles (List[Dict[str, str]]): A list of dictionaries representing Bitcoin news articles.
60
+ Each dictionary contains the 'title' and 'url' of the article.
61
+
62
+ Returns:
63
+ Dict[str, any]: A dictionary containing the sentiment score, sentiment label, and keywords.
64
  """
65
+ sentiments = [TextBlob(article["title"]).sentiment.polarity for article in articles]
66
+ avg_sentiment = np.mean(sentiments) if sentiments else 0
67
+ sentiment_label = "Positive 😊" if avg_sentiment > 0 else "Negative 😡" if avg_sentiment < 0 else "Neutral 😐"
68
+ keywords = list(set([word for article in articles for word in article["title"].split()[:5]]))
69
+
70
+ return {
71
+ "sentiment_score": avg_sentiment,
72
+ "sentiment_label": sentiment_label,
73
+ "keywords": keywords
74
+ }
75
 
76
  ### 🔹 2. Analyze News Sentiment ###
77
  @tool