Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,6 +4,7 @@ import requests
|
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
|
|
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
|
@@ -32,40 +33,9 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 32 |
return f"The current local time in {timezone} is: {local_time}"
|
| 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:
|
| 71 |
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
|
@@ -86,7 +56,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 86 |
|
| 87 |
agent = CodeAgent(
|
| 88 |
model=model,
|
| 89 |
-
tools=[final_answer], ## add your tools here (don't remove final answer)
|
| 90 |
max_steps=6,
|
| 91 |
verbosity_level=1,
|
| 92 |
grammar=None,
|
|
|
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
| 7 |
+
from tools.unit_conversion import UnitConversionTool
|
| 8 |
|
| 9 |
from Gradio_UI import GradioUI
|
| 10 |
|
|
|
|
| 33 |
return f"The current local time in {timezone} is: {local_time}"
|
| 34 |
except Exception as e:
|
| 35 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 36 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
final_answer = FinalAnswerTool()
|
| 38 |
+
unit_conversion = UnitConversionTool()
|
| 39 |
|
| 40 |
# 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:
|
| 41 |
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
|
|
|
| 56 |
|
| 57 |
agent = CodeAgent(
|
| 58 |
model=model,
|
| 59 |
+
tools=[final_answer, unit_conversion], ## add your tools here (don't remove final answer)
|
| 60 |
max_steps=6,
|
| 61 |
verbosity_level=1,
|
| 62 |
grammar=None,
|