Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,8 +1,7 @@
|
|
| 1 |
-
from smolagents import CodeAgent, HfApiModel, tool
|
| 2 |
import requests
|
| 3 |
from tools.final_answer import FinalAnswerTool
|
| 4 |
from Gradio_UI import GradioUI
|
| 5 |
-
from duckduckgo_search import duckduckgo_search
|
| 6 |
|
| 7 |
@tool
|
| 8 |
def get_btc_price() -> str:
|
|
@@ -15,53 +14,50 @@ def get_btc_price() -> str:
|
|
| 15 |
price = data.get('bitcoin', {}).get('usd')
|
| 16 |
if price is None:
|
| 17 |
return '{"error": "Bitcoin price not found"}'
|
| 18 |
-
return f"The current Bitcoin price is ${price:
|
| 19 |
|
| 20 |
@tool
|
| 21 |
-
def
|
| 22 |
-
"""
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
return f"
|
| 34 |
-
elif numeric_price > 30000:
|
| 35 |
-
return f"Market analysis ({price}): Neutral trend detected. Consider holding."
|
| 36 |
else:
|
| 37 |
-
return
|
| 38 |
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
info += f"{result['title']}: {result['url']}\n"
|
| 53 |
-
return info
|
| 54 |
|
| 55 |
-
#
|
| 56 |
agent = CodeAgent(
|
| 57 |
-
model=
|
| 58 |
-
|
| 59 |
-
max_tokens=2096,
|
| 60 |
-
temperature=0.5
|
| 61 |
-
),
|
| 62 |
-
tools=[get_btc_price, get_btc_confidence_conseils, get_btc_info, FinalAnswerTool()],
|
| 63 |
max_steps=6,
|
| 64 |
-
verbosity_level=1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
)
|
| 66 |
|
| 67 |
# Launch the Gradio interface
|
|
|
|
| 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 |
|
| 6 |
@tool
|
| 7 |
def get_btc_price() -> str:
|
|
|
|
| 14 |
price = data.get('bitcoin', {}).get('usd')
|
| 15 |
if price is None:
|
| 16 |
return '{"error": "Bitcoin price not found"}'
|
| 17 |
+
return f"The current Bitcoin price is ${price:.2f} USD."
|
| 18 |
|
| 19 |
@tool
|
| 20 |
+
def get_btc_data(query: str) -> str:
|
| 21 |
+
"""Fetches Bitcoin data using the CoinGecko API."""
|
| 22 |
+
url = f"https://api.coingecko.com/api/v3/coins/bitcoin?localization=false&tickers=false&market_data=true&community_data=false&developer_data=false&sparkline=false"
|
| 23 |
+
response = requests.get(url)
|
| 24 |
+
if response.status_code != 200:
|
| 25 |
+
return '{"error": "Failed to fetch Bitcoin data"}'
|
| 26 |
+
data = response.json()
|
| 27 |
+
if query == "price":
|
| 28 |
+
return f"The current Bitcoin price is ${data['market_data']['current_price']['usd']:.2f} USD."
|
| 29 |
+
elif query == "market_cap":
|
| 30 |
+
return f"The current Bitcoin market capitalization is ${data['market_data']['market_cap']['usd']:.2f} USD."
|
| 31 |
+
elif query == "circulating_supply":
|
| 32 |
+
return f"The current Bitcoin circulating supply is {data['market_data']['circulating_supply']:.2f} BTC."
|
|
|
|
|
|
|
| 33 |
else:
|
| 34 |
+
return '{"error": "Invalid query"}'
|
| 35 |
|
| 36 |
+
# Initialize the FinalAnswerTool
|
| 37 |
+
final_answer = FinalAnswerTool()
|
| 38 |
+
|
| 39 |
+
# Load the DuckDuckGoSearchTool
|
| 40 |
+
duckduckgo_search_tool = load_tool("smolai/duckduckgo-search-tool", trust_remote_code=True)
|
| 41 |
+
|
| 42 |
+
# Initialize the model
|
| 43 |
+
model = HfApiModel(
|
| 44 |
+
max_tokens=2096,
|
| 45 |
+
temperature=0.5,
|
| 46 |
+
model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
|
| 47 |
+
custom_role_conversions=None,
|
| 48 |
+
)
|
|
|
|
|
|
|
| 49 |
|
| 50 |
+
# Create the agent
|
| 51 |
agent = CodeAgent(
|
| 52 |
+
model=model,
|
| 53 |
+
tools=[get_btc_price, get_btc_data, duckduckgo_search_tool, final_answer], # Add your tools here
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
max_steps=6,
|
| 55 |
+
verbosity_level=1,
|
| 56 |
+
grammar=None,
|
| 57 |
+
planning_interval=None,
|
| 58 |
+
name=None,
|
| 59 |
+
description=None,
|
| 60 |
+
prompt_templates=None # Set to None if not using prompt templates
|
| 61 |
)
|
| 62 |
|
| 63 |
# Launch the Gradio interface
|