Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -51,15 +51,27 @@ def compute_moving_average(prices, window):
|
|
| 51 |
|
| 52 |
### 🔹 1. Fetch Latest BTC News ###
|
| 53 |
@tool
|
| 54 |
-
def
|
| 55 |
"""
|
| 56 |
-
|
| 57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
"""
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 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
|