Spaces:
Sleeping
Sleeping
peterbonnesoeur
commited on
Commit
·
9e5b98a
1
Parent(s):
6feec09
Added tool
Browse files- .gitignore +15 -0
- app.py +7 -0
- requirements.txt +1 -0
- tool.py +28 -0
.gitignore
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Python-generated files
|
2 |
+
__pycache__/
|
3 |
+
*.py[oc]
|
4 |
+
build/
|
5 |
+
dist/
|
6 |
+
wheels/
|
7 |
+
*.egg-info
|
8 |
+
.python-version
|
9 |
+
uv.lock
|
10 |
+
pyproject.toml
|
11 |
+
|
12 |
+
# Virtual environments
|
13 |
+
.venv
|
14 |
+
|
15 |
+
.codegpt
|
app.py
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from smolagents import launch_gradio_demo
|
2 |
+
from typing import Optional
|
3 |
+
from tool import UnitConversionTool
|
4 |
+
|
5 |
+
tool = TimeZoneConversionTool()
|
6 |
+
|
7 |
+
launch_gradio_demo(tool)
|
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
smolagents
|
tool.py
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from smolagents import Tool
|
2 |
+
|
3 |
+
class UnitConversionTool(Tool):
|
4 |
+
name = "unit_converter"
|
5 |
+
description = "Converts values between units (e.g., kilometers to miles)."
|
6 |
+
inputs = {
|
7 |
+
"value": {"type": "number", "description": "Value to convert"},
|
8 |
+
"from_unit": {"type": "string", "description": "Unit to convert from (e.g., 'km', 'kg')"},
|
9 |
+
"to_unit": {"type": "string", "description": "Unit to convert to (e.g., 'miles', 'lbs')"}
|
10 |
+
}
|
11 |
+
output_type = "number"
|
12 |
+
|
13 |
+
def forward(self, value: float, from_unit: str, to_unit: str):
|
14 |
+
conversions = {
|
15 |
+
("km", "miles"): 0.621371,
|
16 |
+
("miles", "km"): 1.60934,
|
17 |
+
("kg", "lbs"): 2.20462,
|
18 |
+
("lbs", "kg"): 0.453592,
|
19 |
+
("C", "F"): lambda x: x * 9/5 + 32,
|
20 |
+
("F", "C"): lambda x: (x - 32) * 5/9
|
21 |
+
}
|
22 |
+
conversion = conversions.get((from_unit, to_unit))
|
23 |
+
if callable(conversion):
|
24 |
+
return conversion(value)
|
25 |
+
elif conversion:
|
26 |
+
return value * conversion
|
27 |
+
else:
|
28 |
+
return "Conversion not supported."
|