Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,8 @@
|
|
| 1 |
-
from smolagents import CodeAgent,
|
| 2 |
import requests
|
| 3 |
from tools.final_answer import FinalAnswerTool
|
| 4 |
from Gradio_UI import GradioUI
|
|
|
|
| 5 |
|
| 6 |
@tool
|
| 7 |
def get_btc_price() -> str:
|
|
@@ -18,15 +19,17 @@ def get_btc_price() -> str:
|
|
| 18 |
|
| 19 |
@tool
|
| 20 |
def get_btc_news() -> str:
|
| 21 |
-
"""Fetches the latest Bitcoin news
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
if not
|
| 25 |
-
return
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
|
|
|
|
|
|
| 30 |
|
| 31 |
# Initialize the FinalAnswerTool
|
| 32 |
final_answer = FinalAnswerTool()
|
|
@@ -39,10 +42,6 @@ model = HfApiModel(
|
|
| 39 |
custom_role_conversions=None,
|
| 40 |
)
|
| 41 |
|
| 42 |
-
# Load additional tools if needed
|
| 43 |
-
# For example, to load an image generation tool:
|
| 44 |
-
# image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 45 |
-
|
| 46 |
# Create the agent
|
| 47 |
agent = CodeAgent(
|
| 48 |
model=model,
|
|
|
|
| 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
|
| 5 |
+
from duckduckgo_search import ddg_search
|
| 6 |
|
| 7 |
@tool
|
| 8 |
def get_btc_price() -> str:
|
|
|
|
| 19 |
|
| 20 |
@tool
|
| 21 |
def get_btc_news() -> str:
|
| 22 |
+
"""Fetches the latest Bitcoin news titles and meta descriptions."""
|
| 23 |
+
query = "Bitcoin news"
|
| 24 |
+
results = ddg_search(query, max_results=5) # Adjust max_results as needed
|
| 25 |
+
if not results:
|
| 26 |
+
return "No news found."
|
| 27 |
+
news_list = []
|
| 28 |
+
for result in results:
|
| 29 |
+
title = result.get('title', 'No title')
|
| 30 |
+
meta_description = result.get('snippet', 'No description available')
|
| 31 |
+
news_list.append(f"**{title}**\n{meta_description}\n")
|
| 32 |
+
return "\n".join(news_list)
|
| 33 |
|
| 34 |
# Initialize the FinalAnswerTool
|
| 35 |
final_answer = FinalAnswerTool()
|
|
|
|
| 42 |
custom_role_conversions=None,
|
| 43 |
)
|
| 44 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
# Create the agent
|
| 46 |
agent = CodeAgent(
|
| 47 |
model=model,
|