Update app.py
Browse files
app.py
CHANGED
|
@@ -9,14 +9,82 @@ from Gradio_UI import GradioUI
|
|
| 9 |
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
@tool
|
| 12 |
-
def
|
| 13 |
-
|
| 14 |
-
"""A tool that does nothing yet
|
| 15 |
Args:
|
| 16 |
-
|
| 17 |
-
arg2: the second argument
|
| 18 |
"""
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
@@ -46,6 +114,8 @@ model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may
|
|
| 46 |
custom_role_conversions=None,
|
| 47 |
)
|
| 48 |
|
|
|
|
|
|
|
| 49 |
|
| 50 |
# Import tool from Hub
|
| 51 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
|
@@ -55,12 +125,12 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 55 |
|
| 56 |
agent = CodeAgent(
|
| 57 |
model=model,
|
| 58 |
-
tools=[final_answer
|
| 59 |
max_steps=6,
|
| 60 |
verbosity_level=1,
|
| 61 |
grammar=None,
|
| 62 |
planning_interval=None,
|
| 63 |
-
name=
|
| 64 |
description=None,
|
| 65 |
prompt_templates=prompt_templates
|
| 66 |
)
|
|
|
|
| 9 |
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
@tool
|
| 12 |
+
def get_weather(location: str) -> str:
|
| 13 |
+
"""Get the current weather for a specified location.
|
|
|
|
| 14 |
Args:
|
| 15 |
+
location: A city, region, or country name, such as 'Beijing', 'Tokyo', or 'New York'.
|
|
|
|
| 16 |
"""
|
| 17 |
+
try:
|
| 18 |
+
url = f"https://wttr.in/{location}?format=j1"
|
| 19 |
+
response = requests.get(url, timeout=10)
|
| 20 |
+
response.raise_for_status()
|
| 21 |
+
data = response.json()
|
| 22 |
+
|
| 23 |
+
current = data["current_condition"][0]
|
| 24 |
+
|
| 25 |
+
temp_c = current.get("temp_C", "Unknown")
|
| 26 |
+
feels_like_c = current.get("FeelsLikeC", "Unknown")
|
| 27 |
+
humidity = current.get("humidity", "Unknown")
|
| 28 |
+
weather_desc = current.get("weatherDesc", [{}])[0].get("value", "Unknown")
|
| 29 |
+
wind_kph = current.get("windspeedKmph", "Unknown")
|
| 30 |
+
|
| 31 |
+
return (
|
| 32 |
+
f"Current weather in {location}:\n"
|
| 33 |
+
f"- Condition: {weather_desc}\n"
|
| 34 |
+
f"- Temperature: {temp_c}°C\n"
|
| 35 |
+
f"- Feels like: {feels_like_c}°C\n"
|
| 36 |
+
f"- Humidity: {humidity}%\n"
|
| 37 |
+
f"- Wind speed: {wind_kph} km/h"
|
| 38 |
+
)
|
| 39 |
+
except Exception as e:
|
| 40 |
+
return f"Error fetching weather for '{location}': {str(e)}"
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
@tool
|
| 44 |
+
def get_nba_games(date: str) -> str:
|
| 45 |
+
"""Get NBA game results for a specific date.
|
| 46 |
+
Args:
|
| 47 |
+
date: A date in YYYY-MM-DD format, for example '2026-03-08'.
|
| 48 |
+
"""
|
| 49 |
+
try:
|
| 50 |
+
url = "https://www.balldontlie.io/api/v1/games"
|
| 51 |
+
params = {
|
| 52 |
+
"dates[]": date,
|
| 53 |
+
"per_page": 100
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
response = requests.get(url, params=params, timeout=10)
|
| 57 |
+
response.raise_for_status()
|
| 58 |
+
data = response.json()
|
| 59 |
+
|
| 60 |
+
games = data.get("data", [])
|
| 61 |
+
if not games:
|
| 62 |
+
return f"No NBA games found for {date}."
|
| 63 |
+
|
| 64 |
+
results = [f"NBA games on {date}:"]
|
| 65 |
+
for game in games:
|
| 66 |
+
home_team = game["home_team"]["full_name"]
|
| 67 |
+
visitor_team = game["visitor_team"]["full_name"]
|
| 68 |
+
home_score = game.get("home_team_score", 0)
|
| 69 |
+
visitor_score = game.get("visitor_team_score", 0)
|
| 70 |
+
status = game.get("status", "Unknown")
|
| 71 |
+
|
| 72 |
+
if home_score > visitor_score:
|
| 73 |
+
winner = home_team
|
| 74 |
+
elif visitor_score > home_score:
|
| 75 |
+
winner = visitor_team
|
| 76 |
+
else:
|
| 77 |
+
winner = "Tie / Not finished"
|
| 78 |
+
|
| 79 |
+
results.append(
|
| 80 |
+
f"- {visitor_team} {visitor_score} : {home_score} {home_team} "
|
| 81 |
+
f"(Status: {status}, Winner: {winner})"
|
| 82 |
+
)
|
| 83 |
+
|
| 84 |
+
return "\n".join(results)
|
| 85 |
+
|
| 86 |
+
except Exception as e:
|
| 87 |
+
return f"Error fetching NBA games for '{date}': {str(e)}"
|
| 88 |
|
| 89 |
@tool
|
| 90 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 114 |
custom_role_conversions=None,
|
| 115 |
)
|
| 116 |
|
| 117 |
+
# Search tool
|
| 118 |
+
search_tool = DuckDuckGoSearchTool()
|
| 119 |
|
| 120 |
# Import tool from Hub
|
| 121 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
|
|
|
| 125 |
|
| 126 |
agent = CodeAgent(
|
| 127 |
model=model,
|
| 128 |
+
tools=[final_answer, my_custom_tool, get_nba_games, get_weather, get_current_time_in_timezone, search_tool, image_generation_tool]
|
| 129 |
max_steps=6,
|
| 130 |
verbosity_level=1,
|
| 131 |
grammar=None,
|
| 132 |
planning_interval=None,
|
| 133 |
+
name="Qiang Chen",
|
| 134 |
description=None,
|
| 135 |
prompt_templates=prompt_templates
|
| 136 |
)
|