Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -33,15 +33,16 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
33 |
except Exception as e:
|
34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
35 |
|
36 |
-
@tool
|
37 |
def convert_units(value: float, from_unit: str, to_unit: str) -> str:
|
38 |
-
"""Converts common units (length, weight, temperature).
|
|
|
39 |
Args:
|
40 |
value: The numerical value to convert
|
41 |
from_unit: The original unit (e.g., 'km', 'kg', 'C')
|
42 |
to_unit: The target unit (e.g., 'miles', 'lb', 'F')
|
43 |
"""
|
44 |
-
conversions
|
45 |
('km', 'miles'): lambda x: x * 0.621371,
|
46 |
('miles', 'km'): lambda x: x / 0.621371,
|
47 |
('kg', 'lb'): lambda x: x * 2.20462,
|
@@ -49,11 +50,10 @@ def convert_units(value: float, from_unit: str, to_unit: str) -> str:
|
|
49 |
('C', 'F'): lambda x: (x * 9/5) + 32,
|
50 |
('F', 'C'): lambda x: (x - 32) * 5/9
|
51 |
}
|
52 |
-
# dictionary which maps (from_unit, to_unit) tuples to simple math functions (lambda) that perform the actual conversion
|
53 |
try:
|
54 |
func = conversions[(from_unit.lower(), to_unit.lower())]
|
55 |
result = func(value)
|
56 |
-
return f"
|
57 |
except KeyError:
|
58 |
return f"Unsupported conversion from {from_unit} to {to_unit}."
|
59 |
except Exception as e:
|
|
|
33 |
except Exception as e:
|
34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
35 |
|
36 |
+
@tool
|
37 |
def convert_units(value: float, from_unit: str, to_unit: str) -> str:
|
38 |
+
"""Converts between common units (length, weight, temperature). Useful for unit conversion tasks.
|
39 |
+
|
40 |
Args:
|
41 |
value: The numerical value to convert
|
42 |
from_unit: The original unit (e.g., 'km', 'kg', 'C')
|
43 |
to_unit: The target unit (e.g., 'miles', 'lb', 'F')
|
44 |
"""
|
45 |
+
conversions = {
|
46 |
('km', 'miles'): lambda x: x * 0.621371,
|
47 |
('miles', 'km'): lambda x: x / 0.621371,
|
48 |
('kg', 'lb'): lambda x: x * 2.20462,
|
|
|
50 |
('C', 'F'): lambda x: (x * 9/5) + 32,
|
51 |
('F', 'C'): lambda x: (x - 32) * 5/9
|
52 |
}
|
|
|
53 |
try:
|
54 |
func = conversions[(from_unit.lower(), to_unit.lower())]
|
55 |
result = func(value)
|
56 |
+
return f"{value} {from_unit} = {result:.2f} {to_unit}"
|
57 |
except KeyError:
|
58 |
return f"Unsupported conversion from {from_unit} to {to_unit}."
|
59 |
except Exception as e:
|