Spaces:
Sleeping
Sleeping
Update app.py
Browse filesadded a weather fetching too
app.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
from smolagents import CodeAgent,DuckDuckGoSearchTool,
|
| 2 |
import datetime
|
| 3 |
import requests
|
| 4 |
import pytz
|
|
@@ -34,12 +34,35 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 35 |
|
| 36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
final_answer = FinalAnswerTool()
|
| 38 |
|
| 39 |
# 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:
|
| 40 |
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
| 41 |
|
| 42 |
-
model =
|
| 43 |
max_tokens=2096,
|
| 44 |
temperature=0.5,
|
| 45 |
model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
|
|
|
|
| 1 |
+
from smolagents import CodeAgent,DuckDuckGoSearchTool, InferenceClientModel,load_tool,tool
|
| 2 |
import datetime
|
| 3 |
import requests
|
| 4 |
import pytz
|
|
|
|
| 34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 35 |
|
| 36 |
|
| 37 |
+
@tool
|
| 38 |
+
def get_weather(location: str) -> str:
|
| 39 |
+
"""
|
| 40 |
+
A tool that fetches the current weather for a specified location.
|
| 41 |
+
Args:
|
| 42 |
+
location: A string representing a valid location (e.g., 'New York').
|
| 43 |
+
Returns:
|
| 44 |
+
A string describing the temperature and humidity, or an error message.
|
| 45 |
+
"""
|
| 46 |
+
try:
|
| 47 |
+
async def fetch_weather(loc: str) -> str:
|
| 48 |
+
async with python_weather.Client(unit=python_weather.IMPERIAL) as client:
|
| 49 |
+
weather = await client.get(loc)
|
| 50 |
+
return (
|
| 51 |
+
f"The temperature in {loc} is {weather.temperature}°F "
|
| 52 |
+
f"and the humidity is {weather.humidity}%."
|
| 53 |
+
)
|
| 54 |
+
# Run the async function in the event loop
|
| 55 |
+
return await(fetch_weather(location))
|
| 56 |
+
except Exception as e:
|
| 57 |
+
return f"Error fetching weather for '{location}': {str(e)}"
|
| 58 |
+
|
| 59 |
+
|
| 60 |
final_answer = FinalAnswerTool()
|
| 61 |
|
| 62 |
# 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:
|
| 63 |
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
| 64 |
|
| 65 |
+
model = InferenceClientModel(
|
| 66 |
max_tokens=2096,
|
| 67 |
temperature=0.5,
|
| 68 |
model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
|