Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,27 +1,21 @@
|
|
| 1 |
-
from smolagents import CodeAgent,
|
| 2 |
-
import datetime
|
| 3 |
import requests
|
| 4 |
-
import pytz
|
| 5 |
import yaml
|
| 6 |
-
from huggingface_hub import InferenceClient
|
| 7 |
from tools.final_answer import FinalAnswerTool
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
-
# ✅ Initialize the Hugging Face Inference Client
|
| 11 |
-
client = InferenceClient()
|
| 12 |
-
|
| 13 |
# ✅ Custom Tool: Snowfall Forecast Lookup
|
| 14 |
@tool
|
| 15 |
def get_snowfall_forecast(city: str, date: str) -> str:
|
| 16 |
"""
|
| 17 |
Fetches the expected snowfall in a given city on a specified date.
|
| 18 |
|
| 19 |
-
|
| 20 |
-
city (str): The name of the city for which snowfall data is required
|
| 21 |
date (str): The date in YYYY-MM-DD format for which the snowfall forecast is needed.
|
| 22 |
|
| 23 |
Returns:
|
| 24 |
-
str:
|
| 25 |
"""
|
| 26 |
try:
|
| 27 |
# Geocode the city to get latitude & longitude
|
|
@@ -55,19 +49,14 @@ model = HfApiModel(
|
|
| 55 |
max_tokens=2096,
|
| 56 |
temperature=0.5,
|
| 57 |
model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
|
| 58 |
-
custom_role_conversions=None,
|
| 59 |
)
|
| 60 |
|
| 61 |
# ✅ Create the AI Agent with Tools
|
| 62 |
agent = CodeAgent(
|
| 63 |
model=model,
|
| 64 |
-
tools=[final_answer, get_snowfall_forecast], #
|
| 65 |
max_steps=6,
|
| 66 |
verbosity_level=1,
|
| 67 |
-
grammar=None,
|
| 68 |
-
planning_interval=None,
|
| 69 |
-
name="WeatherBot",
|
| 70 |
-
description="An AI agent that fetches snowfall forecasts for any city on a given date.",
|
| 71 |
)
|
| 72 |
|
| 73 |
# ✅ Launch the Gradio UI
|
|
|
|
| 1 |
+
from smolagents import CodeAgent, HfApiModel, load_tool, tool
|
|
|
|
| 2 |
import requests
|
|
|
|
| 3 |
import yaml
|
|
|
|
| 4 |
from tools.final_answer import FinalAnswerTool
|
| 5 |
from Gradio_UI import GradioUI
|
| 6 |
|
|
|
|
|
|
|
|
|
|
| 7 |
# ✅ Custom Tool: Snowfall Forecast Lookup
|
| 8 |
@tool
|
| 9 |
def get_snowfall_forecast(city: str, date: str) -> str:
|
| 10 |
"""
|
| 11 |
Fetches the expected snowfall in a given city on a specified date.
|
| 12 |
|
| 13 |
+
Parameters:
|
| 14 |
+
city (str): The name of the city for which snowfall data is required. Example: "Denver".
|
| 15 |
date (str): The date in YYYY-MM-DD format for which the snowfall forecast is needed.
|
| 16 |
|
| 17 |
Returns:
|
| 18 |
+
str: A message with the expected snowfall in centimeters or an error message if data is unavailable.
|
| 19 |
"""
|
| 20 |
try:
|
| 21 |
# Geocode the city to get latitude & longitude
|
|
|
|
| 49 |
max_tokens=2096,
|
| 50 |
temperature=0.5,
|
| 51 |
model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
|
|
|
|
| 52 |
)
|
| 53 |
|
| 54 |
# ✅ Create the AI Agent with Tools
|
| 55 |
agent = CodeAgent(
|
| 56 |
model=model,
|
| 57 |
+
tools=[final_answer, get_snowfall_forecast], # Snowfall Forecast Tool Added
|
| 58 |
max_steps=6,
|
| 59 |
verbosity_level=1,
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
)
|
| 61 |
|
| 62 |
# ✅ Launch the Gradio UI
|