Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,8 @@
|
|
|
|
|
|
|
|
|
|
1 |
from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
|
2 |
-
import os
|
3 |
import datetime
|
4 |
import requests
|
5 |
import pytz
|
@@ -10,35 +13,33 @@ from Gradio_UI import GradioUI
|
|
10 |
|
11 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
12 |
@tool
|
13 |
-
def
|
14 |
#Keep this format for the description / args / args description but feel free to modify the tool
|
15 |
-
"""A tool
|
16 |
Args:
|
17 |
-
|
18 |
-
|
19 |
"""
|
20 |
-
|
21 |
-
symbol =
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
-
|
25 |
-
|
26 |
-
headers = {"accept": "application/json"}
|
27 |
|
28 |
-
try:
|
29 |
-
#make request to endpoint
|
30 |
-
response = requests.get(url, headers=headers)
|
31 |
-
|
32 |
-
#process response
|
33 |
-
if response.status_code == 200:
|
34 |
-
data = response.json()
|
35 |
-
usd_value = data[symbol][currency]
|
36 |
-
return f"The price of " + symbol + " in " + currency + " is " + f"${usd_value:,.2f}" #format as currency
|
37 |
else:
|
38 |
-
|
39 |
-
return f"
|
|
|
40 |
except Exception as e:
|
41 |
-
return f"Error fetching
|
|
|
|
|
42 |
|
43 |
@tool
|
44 |
def get_current_time_in_timezone(timezone: str) -> str:
|
@@ -68,12 +69,6 @@ model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may
|
|
68 |
custom_role_conversions=None,
|
69 |
)
|
70 |
|
71 |
-
# model = HfApiModel(
|
72 |
-
# model_id="deepseek-ai/DeepSeek-R1",
|
73 |
-
# provider="together",
|
74 |
-
# api_key=os.getenv("together_key") # Fetch API key from environment
|
75 |
-
# )
|
76 |
-
|
77 |
|
78 |
# Import tool from Hub
|
79 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
@@ -83,7 +78,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
83 |
|
84 |
agent = CodeAgent(
|
85 |
model=model,
|
86 |
-
tools=[final_answer,
|
87 |
max_steps=6,
|
88 |
verbosity_level=1,
|
89 |
grammar=None,
|
|
|
1 |
+
#!pip install -q yfinance
|
2 |
+
|
3 |
+
|
4 |
+
import yfinance as yf
|
5 |
from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
|
|
|
6 |
import datetime
|
7 |
import requests
|
8 |
import pytz
|
|
|
13 |
|
14 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
15 |
@tool
|
16 |
+
def my_custom_tool(arg1:str, arg2:str)-> str: #it's import to specify the return type
|
17 |
#Keep this format for the description / args / args description but feel free to modify the tool
|
18 |
+
"""A tool fetches stock information of the provided symbol from Yahoo Finance API
|
19 |
Args:
|
20 |
+
arg1: company ticker symbol
|
21 |
+
arg2: information requested from the company data dict
|
22 |
"""
|
23 |
+
|
24 |
+
symbol: str = arg1.upper()
|
25 |
+
information: str = arg2.lower()
|
26 |
+
|
27 |
+
try:
|
28 |
+
|
29 |
+
tick = yf.Ticker(symbol)
|
30 |
+
company_data = tick.info
|
31 |
|
32 |
+
if information in company_data:
|
33 |
+
return f"{symbol} : {information} = {company_data[information]}"
|
|
|
34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
else:
|
36 |
+
available_keys = ", ".join(company_data.keys())
|
37 |
+
return f"Request information '{information}' is not available for {symbol}. Available informtion {available_keys} "
|
38 |
+
|
39 |
except Exception as e:
|
40 |
+
return f"Error fetching data for {symbol}: {str(e)}"
|
41 |
+
|
42 |
+
# return "What magic will you build ?"
|
43 |
|
44 |
@tool
|
45 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
69 |
custom_role_conversions=None,
|
70 |
)
|
71 |
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
|
73 |
# Import tool from Hub
|
74 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
|
|
78 |
|
79 |
agent = CodeAgent(
|
80 |
model=model,
|
81 |
+
tools=[final_answer, get_current_time_in_timezone, image_generation_tool,my_custom_tool], ## add your tools here (don't remove final answer)
|
82 |
max_steps=6,
|
83 |
verbosity_level=1,
|
84 |
grammar=None,
|