Spaces:
Runtime error
Runtime error
our first tool we share
Browse files- app.py +5 -0
- requirements.txt +1 -0
- tool.py +37 -0
app.py
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from smolagents import launch_gradio_demo
|
| 2 |
+
from tool import SimpleTool
|
| 3 |
+
|
| 4 |
+
tool = SimpleTool()
|
| 5 |
+
launch_gradio_demo(tool)
|
requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
smolagents
|
tool.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from smolagents import Tool
|
| 2 |
+
from typing import Any, Optional
|
| 3 |
+
|
| 4 |
+
class SimpleTool(Tool):
|
| 5 |
+
name = "get_weather_data"
|
| 6 |
+
description = "Returns sample weather data for a given city."
|
| 7 |
+
inputs = {'city': {'type': 'string', 'description': 'Name of the city (new york, london, or tokyo)'}}
|
| 8 |
+
output_type = "object"
|
| 9 |
+
|
| 10 |
+
def forward(self, city: str) -> dict:
|
| 11 |
+
"""
|
| 12 |
+
Returns sample weather data for a given city.
|
| 13 |
+
|
| 14 |
+
Args:
|
| 15 |
+
city: Name of the city (new york, london, or tokyo)
|
| 16 |
+
"""
|
| 17 |
+
# Sample data for demonstration
|
| 18 |
+
sample_data = {
|
| 19 |
+
"new york": {
|
| 20 |
+
"temps": [72, 75, 65, 68, 70, 74, 73],
|
| 21 |
+
"rain": [0, 0.2, 0.5, 0, 0, 0.1, 0],
|
| 22 |
+
"unit": "F"
|
| 23 |
+
},
|
| 24 |
+
"london": {
|
| 25 |
+
"temps": [15, 14, 16, 13, 15, 17, 16],
|
| 26 |
+
"rain": [0.5, 0.2, 0, 0.1, 0.3, 0, 0.2],
|
| 27 |
+
"unit": "C"
|
| 28 |
+
},
|
| 29 |
+
"tokyo": {
|
| 30 |
+
"temps": [22, 24, 23, 25, 26, 25, 22],
|
| 31 |
+
"rain": [0, 0, 0.3, 0.2, 0, 0, 0.1],
|
| 32 |
+
"unit": "C"
|
| 33 |
+
}
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
city_lower = city.lower()
|
| 37 |
+
return sample_data.get(city_lower, {"error": f"No data for {city}"})
|