zerito commited on
Commit
f755820
·
verified ·
1 Parent(s): be2fc79

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -42
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:,.2f} USD."
19
 
20
  @tool
21
- def get_btc_confidence_conseils(price: str) -> str:
22
- """Analyzes Bitcoin market confidence using price data.
23
-
24
- Args:
25
- price (str): The current Bitcoin price in USD format (e.g., "$50,000.00")
26
-
27
- Returns:
28
- str: Market analysis and trading advice based on current conditions
29
- """
30
- numeric_price = float(price.replace("$", "").replace(",", ""))
31
-
32
- if numeric_price > 50000:
33
- return f"Market analysis ({price}): Bullish trend detected. Consider buying."
34
- elif numeric_price > 30000:
35
- return f"Market analysis ({price}): Neutral trend detected. Consider holding."
36
  else:
37
- return f"Market analysis ({price}): Bearish trend detected. Consider selling."
38
 
39
- @tool
40
- def get_btc_info(query: str) -> str:
41
- """Gathers information on Bitcoin using DuckDuckGo search.
42
-
43
- Args:
44
- query (str): Search query related to Bitcoin (e.g., "Bitcoin price", "Bitcoin news")
45
-
46
- Returns:
47
- str: Relevant information on Bitcoin based on the search query
48
- """
49
- results = duckduckgo_search(query, user_agent='Mozilla/5.0', max_results=5)
50
- info = ""
51
- for result in results:
52
- info += f"{result['title']}: {result['url']}\n"
53
- return info
54
 
55
- # Initialize the agent with all tools
56
  agent = CodeAgent(
57
- model=HfApiModel(
58
- model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
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