SheikhIrtiza commited on
Commit
8cbcd36
·
verified ·
1 Parent(s): 5fbc3fe

our first tool we share

Browse files
Files changed (3) hide show
  1. app.py +5 -0
  2. requirements.txt +1 -0
  3. 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}"})