Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,7 +4,8 @@ import requests
|
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
| 7 |
-
|
|
|
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
|
@@ -18,6 +19,45 @@ def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
|
|
| 18 |
"""
|
| 19 |
return "What magic will you build ?"
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 23 |
"""A tool that fetches the current local time in a specified timezone.
|
|
@@ -55,7 +95,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 55 |
|
| 56 |
agent = CodeAgent(
|
| 57 |
model=model,
|
| 58 |
-
tools=[final_answer], ## add your tools here (don't remove final answer)
|
| 59 |
max_steps=6,
|
| 60 |
verbosity_level=1,
|
| 61 |
grammar=None,
|
|
|
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
| 7 |
+
import requests
|
| 8 |
+
from bs4 import BeautifulSoup
|
| 9 |
from Gradio_UI import GradioUI
|
| 10 |
|
| 11 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
|
|
|
| 19 |
"""
|
| 20 |
return "What magic will you build ?"
|
| 21 |
|
| 22 |
+
@tool
|
| 23 |
+
def get_weather(location: str) -> dict:
|
| 24 |
+
"""
|
| 25 |
+
It gives weather information for a given location from a weather website.
|
| 26 |
+
|
| 27 |
+
Parameters:
|
| 28 |
+
location (str): The location for which to fetch weather data (e.g., city name).
|
| 29 |
+
|
| 30 |
+
Returns:
|
| 31 |
+
dict: A dictionary containing weather information or an error message.
|
| 32 |
+
"""
|
| 33 |
+
# Format the location for URL (e.g., "New York" -> "new-york")
|
| 34 |
+
location = location.replace(" ", "-").lower()
|
| 35 |
+
|
| 36 |
+
# URL of a weather website (e.g., 'https://www.weather.com')
|
| 37 |
+
url = f"https://weather.com/weather/today/l/{location}"
|
| 38 |
+
|
| 39 |
+
# Send a GET request to fetch the HTML content
|
| 40 |
+
try:
|
| 41 |
+
response = requests.get(url)
|
| 42 |
+
response.raise_for_status() # Raise an exception for bad responses
|
| 43 |
+
|
| 44 |
+
# Parse HTML content
|
| 45 |
+
soup = BeautifulSoup(response.text, 'html.parser')
|
| 46 |
+
|
| 47 |
+
# Extract weather information (change selectors according to the website structure)
|
| 48 |
+
temperature = soup.find('span', {'class': 'CurrentConditions--tempValue--3KcTQ'}).text
|
| 49 |
+
description = soup.find('div', {'class': 'CurrentConditions--phraseValue--2xXSr'}).text
|
| 50 |
+
|
| 51 |
+
return {
|
| 52 |
+
"temperature": temperature,
|
| 53 |
+
"description": description,
|
| 54 |
+
"location": location
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
except Exception as e:
|
| 58 |
+
return {"error": f"An error occurred: {e}"}
|
| 59 |
+
|
| 60 |
+
|
| 61 |
@tool
|
| 62 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 63 |
"""A tool that fetches the current local time in a specified timezone.
|
|
|
|
| 95 |
|
| 96 |
agent = CodeAgent(
|
| 97 |
model=model,
|
| 98 |
+
tools=[final_answer, get_weather], ## add your tools here (don't remove final answer)
|
| 99 |
max_steps=6,
|
| 100 |
verbosity_level=1,
|
| 101 |
grammar=None,
|