Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -33,7 +33,38 @@ 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 |
|
|
|
|
| 37 |
final_answer = FinalAnswerTool()
|
| 38 |
|
| 39 |
# If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
|
|
|
|
| 33 |
except Exception as e:
|
| 34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 35 |
|
| 36 |
+
@tool
|
| 37 |
+
def unit_conversion(value: float, from_unit: str, to_unit: str) -> str:
|
| 38 |
+
"""A tool that converts units like distance, weight, and temperature.
|
| 39 |
+
|
| 40 |
+
Args:
|
| 41 |
+
value: The numerical value to convert.
|
| 42 |
+
from_unit: The unit to convert from (e.g., 'miles', 'celsius').
|
| 43 |
+
to_unit: The unit to convert to (e.g., 'kilometers', 'fahrenheit').
|
| 44 |
+
|
| 45 |
+
Returns:
|
| 46 |
+
The converted value in the target unit.
|
| 47 |
+
"""
|
| 48 |
+
|
| 49 |
+
conversion_factors = {
|
| 50 |
+
("miles", "kilometers"): 1.60934,
|
| 51 |
+
("kilometers", "miles"): 0.621371,
|
| 52 |
+
("pounds", "kilograms"): 0.453592,
|
| 53 |
+
("kilograms", "pounds"): 2.20462,
|
| 54 |
+
("celsius", "fahrenheit"): lambda c: (c * 9/5) + 32,
|
| 55 |
+
("fahrenheit", "celsius"): lambda f: (f - 32) * 5/9
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
key = (from_unit.lower(), to_unit.lower())
|
| 59 |
+
|
| 60 |
+
if key in conversion_factors:
|
| 61 |
+
conversion = conversion_factors[key]
|
| 62 |
+
result = conversion(value) if callable(conversion) else value * conversion
|
| 63 |
+
return f"{value} {from_unit} is {result:.2f} {to_unit}."
|
| 64 |
+
else:
|
| 65 |
+
return "Sorry, conversion not supported."
|
| 66 |
|
| 67 |
+
|
| 68 |
final_answer = FinalAnswerTool()
|
| 69 |
|
| 70 |
# If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
|