Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
from smolagents import CodeAgent, HfApiModel, load_tool, tool
|
| 2 |
import requests
|
| 3 |
from tools.final_answer import FinalAnswerTool
|
| 4 |
from Gradio_UI import GradioUI
|
|
@@ -17,32 +17,33 @@ def get_btc_price() -> str:
|
|
| 17 |
return '{"error": "Bitcoin price not found"}'
|
| 18 |
return f"The current Bitcoin price is ${price:.2f} USD."
|
| 19 |
|
| 20 |
-
|
| 21 |
-
# Tool for fetching Bitcoin news using DuckDuckGo search
|
| 22 |
@tool
|
| 23 |
def get_btc_news() -> str:
|
| 24 |
-
"""Fetches the latest Bitcoin news from
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
#
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
|
|
|
|
|
|
| 46 |
|
| 47 |
# Initialize the FinalAnswerTool
|
| 48 |
final_answer = FinalAnswerTool()
|
|
|
|
| 1 |
+
from smolagents import CodeAgent, HfApiModel, load_tool, tool
|
| 2 |
import requests
|
| 3 |
from tools.final_answer import FinalAnswerTool
|
| 4 |
from Gradio_UI import GradioUI
|
|
|
|
| 17 |
return '{"error": "Bitcoin price not found"}'
|
| 18 |
return f"The current Bitcoin price is ${price:.2f} USD."
|
| 19 |
|
| 20 |
+
# Tool for fetching Bitcoin news using NewsData.io API
|
|
|
|
| 21 |
@tool
|
| 22 |
def get_btc_news() -> str:
|
| 23 |
+
"""Fetches the latest Bitcoin news from NewsData.io API."""
|
| 24 |
+
url = "https://newsdata.io/api/1/news"
|
| 25 |
+
params = {
|
| 26 |
+
'apikey': 'YOUR_API_KEY', # Replace with your actual API key
|
| 27 |
+
'q': 'Bitcoin',
|
| 28 |
+
'category': 'crypto',
|
| 29 |
+
'language': 'en',
|
| 30 |
+
'country': 'us',
|
| 31 |
+
'page': 1,
|
| 32 |
+
'size': 5 # Number of news articles to fetch
|
| 33 |
+
}
|
| 34 |
+
response = requests.get(url, params=params)
|
| 35 |
+
if response.status_code != 200:
|
| 36 |
+
return '{"error": "Failed to fetch Bitcoin news"}'
|
| 37 |
+
data = response.json()
|
| 38 |
+
articles = data.get('results', [])
|
| 39 |
+
if not articles:
|
| 40 |
+
return "No relevant news found."
|
| 41 |
+
news_list = []
|
| 42 |
+
for article in articles:
|
| 43 |
+
title = article.get('title', 'No title')
|
| 44 |
+
description = article.get('description', 'No description')
|
| 45 |
+
news_list.append(f"Title: {title}\nDescription: {description}\n")
|
| 46 |
+
return "\n\n".join(news_list)
|
| 47 |
|
| 48 |
# Initialize the FinalAnswerTool
|
| 49 |
final_answer = FinalAnswerTool()
|