Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -8,6 +8,54 @@ from tools.final_answer import FinalAnswerTool
|
|
8 |
|
9 |
from Gradio_UI import GradioUI
|
10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
final_answer = FinalAnswerTool()
|
12 |
|
13 |
# If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
|
@@ -27,7 +75,7 @@ custom_role_conversions=None,
|
|
27 |
# )
|
28 |
|
29 |
|
30 |
-
# Import tool from Hub
|
31 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
32 |
|
33 |
with open("prompts.yaml", 'r') as stream:
|
@@ -35,7 +83,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
35 |
|
36 |
agent = CodeAgent(
|
37 |
model=model,
|
38 |
-
tools=[final_answer,
|
39 |
max_steps=6,
|
40 |
verbosity_level=1,
|
41 |
grammar=None,
|
@@ -46,4 +94,4 @@ agent = CodeAgent(
|
|
46 |
)
|
47 |
|
48 |
|
49 |
-
GradioUI(agent).launch(
|
|
|
8 |
|
9 |
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 get_coin_price(symbol: str, currency: str = "usd")-> str: #it's import to specify the return type
|
14 |
+
#Keep this format for the description / args / args description but feel free to modify the tool
|
15 |
+
"""A tool that fetches the latest price on a cryptocurrency symbol from Coingecko API.
|
16 |
+
Args:
|
17 |
+
symbol: A string representing a valid symbol as CoinGecko's ID, not ticker (e.g., 'bitcoin' not BTC).
|
18 |
+
currency: A string representing the currency the value is returned in (e.g., 'usd').
|
19 |
+
"""
|
20 |
+
# set to lowercase for api compatibility and consistency
|
21 |
+
symbol = symbol.lower()
|
22 |
+
currency = currency.lower()
|
23 |
+
|
24 |
+
#define the endpoint with return headers - https://docs.coingecko.com/v3.0.1/reference/simple-price
|
25 |
+
url = "https://api.coingecko.com/api/v3/simple/price?ids=" + symbol + "&vs_currencies=" + currency
|
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 |
+
# returrn verbose error, so the model can observe and ReAct
|
39 |
+
return f"Error: {response.status_code}, {response.text}"
|
40 |
+
except Exception as e:
|
41 |
+
return f"Error fetching price for '{symbol}' valued in currency '{currency}': {str(e)}"
|
42 |
+
|
43 |
+
@tool
|
44 |
+
def get_current_time_in_timezone(timezone: str) -> str:
|
45 |
+
"""A tool that fetches the current local time in a specified timezone.
|
46 |
+
Args:
|
47 |
+
timezone: A string representing a valid timezone (e.g., 'America/New_York').
|
48 |
+
"""
|
49 |
+
try:
|
50 |
+
# Create timezone object
|
51 |
+
tz = pytz.timezone(timezone)
|
52 |
+
# Get current time in that timezone
|
53 |
+
local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
|
54 |
+
return f"The current local time in {timezone} is: {local_time}"
|
55 |
+
except Exception as e:
|
56 |
+
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
57 |
+
|
58 |
+
|
59 |
final_answer = FinalAnswerTool()
|
60 |
|
61 |
# If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
|
|
|
75 |
# )
|
76 |
|
77 |
|
78 |
+
# Import tool from Hub
|
79 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
80 |
|
81 |
with open("prompts.yaml", 'r') as stream:
|
|
|
83 |
|
84 |
agent = CodeAgent(
|
85 |
model=model,
|
86 |
+
tools=[final_answer, get_coin_price, get_current_time_in_timezone, DuckDuckGoSearchTool()], ## add your tools here (don't remove final answer)
|
87 |
max_steps=6,
|
88 |
verbosity_level=1,
|
89 |
grammar=None,
|
|
|
94 |
)
|
95 |
|
96 |
|
97 |
+
GradioUI(agent).launch()
|