Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,12 +1,11 @@
|
|
| 1 |
-
from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, tool
|
| 2 |
-
import datetime
|
| 3 |
-
import json
|
| 4 |
import requests
|
| 5 |
-
import
|
| 6 |
-
import
|
|
|
|
| 7 |
from tools.final_answer import FinalAnswerTool
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
|
|
|
| 10 |
@tool
|
| 11 |
def get_btc_price() -> str:
|
| 12 |
"""Fetches the current Bitcoin price in USD using the CoinGecko API."""
|
|
@@ -19,7 +18,6 @@ def get_btc_price() -> str:
|
|
| 19 |
if price is None:
|
| 20 |
return '{"error": "Bitcoin price not found"}'
|
| 21 |
return f"The current Bitcoin price is ${price:.2f} USD."
|
| 22 |
-
|
| 23 |
@tool
|
| 24 |
def get_btc_news() -> Dict[str, Any]:
|
| 25 |
"""Fetches the latest Bitcoin news using DuckDuckGo Instant Answer API."""
|
|
@@ -35,24 +33,18 @@ def get_btc_news() -> Dict[str, Any]:
|
|
| 35 |
return {"error": "Failed to fetch BTC news"}
|
| 36 |
|
| 37 |
@tool
|
| 38 |
-
def
|
| 39 |
-
"""
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
|
|
|
|
|
|
| 46 |
|
| 47 |
final_answer = FinalAnswerTool()
|
| 48 |
-
model = HfApiModel(
|
| 49 |
-
max_tokens=1048,
|
| 50 |
-
temperature=0.5,
|
| 51 |
-
model_id='deepseek-ai/DeepSeek-R1-Distill-Qwen-32B',
|
| 52 |
-
custom_role_conversions=None,
|
| 53 |
-
)
|
| 54 |
-
|
| 55 |
-
# Import tool from Hub
|
| 56 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 57 |
|
| 58 |
with open("prompts.yaml", 'r') as stream:
|
|
@@ -60,7 +52,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 60 |
|
| 61 |
agent = CodeAgent(
|
| 62 |
model=model,
|
| 63 |
-
tools=[
|
| 64 |
max_steps=6,
|
| 65 |
verbosity_level=1,
|
| 66 |
grammar=None,
|
|
@@ -70,4 +62,4 @@ agent = CodeAgent(
|
|
| 70 |
prompt_templates=prompt_templates
|
| 71 |
)
|
| 72 |
|
| 73 |
-
GradioUI(agent).launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import requests
|
| 2 |
+
import json
|
| 3 |
+
from typing import Dict, Any
|
| 4 |
+
from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, tool
|
| 5 |
from tools.final_answer import FinalAnswerTool
|
| 6 |
from Gradio_UI import GradioUI
|
| 7 |
|
| 8 |
+
|
| 9 |
@tool
|
| 10 |
def get_btc_price() -> str:
|
| 11 |
"""Fetches the current Bitcoin price in USD using the CoinGecko API."""
|
|
|
|
| 18 |
if price is None:
|
| 19 |
return '{"error": "Bitcoin price not found"}'
|
| 20 |
return f"The current Bitcoin price is ${price:.2f} USD."
|
|
|
|
| 21 |
@tool
|
| 22 |
def get_btc_news() -> Dict[str, Any]:
|
| 23 |
"""Fetches the latest Bitcoin news using DuckDuckGo Instant Answer API."""
|
|
|
|
| 33 |
return {"error": "Failed to fetch BTC news"}
|
| 34 |
|
| 35 |
@tool
|
| 36 |
+
def analyze_btc_news(news: str) -> str:
|
| 37 |
+
"""Analyzes the provided Bitcoin news content using the Qwen AI model."""
|
| 38 |
+
model = HfApiModel(
|
| 39 |
+
max_tokens=1048,
|
| 40 |
+
temperature=0.5,
|
| 41 |
+
model_id='deepseek-ai/DeepSeek-R1-Distill-Qwen-32B',
|
| 42 |
+
custom_role_conversions=None,
|
| 43 |
+
)
|
| 44 |
+
analysis = model.generate(f"Analyze the following Bitcoin news: {news}")
|
| 45 |
+
return analysis
|
| 46 |
|
| 47 |
final_answer = FinalAnswerTool()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 49 |
|
| 50 |
with open("prompts.yaml", 'r') as stream:
|
|
|
|
| 52 |
|
| 53 |
agent = CodeAgent(
|
| 54 |
model=model,
|
| 55 |
+
tools=[get_btc_news, analyze_btc_news, image_generation_tool, final_answer],
|
| 56 |
max_steps=6,
|
| 57 |
verbosity_level=1,
|
| 58 |
grammar=None,
|
|
|
|
| 62 |
prompt_templates=prompt_templates
|
| 63 |
)
|
| 64 |
|
| 65 |
+
GradioUI(agent).launch()
|