Update app.py
#1
by SachinPatil13 - opened
app.py
CHANGED
|
@@ -7,16 +7,69 @@ from tools.final_answer import FinalAnswerTool
|
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
-
|
|
|
|
| 11 |
@tool
|
| 12 |
-
def
|
| 13 |
-
|
| 14 |
-
|
| 15 |
Args:
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
"""
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
@@ -55,7 +108,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 55 |
|
| 56 |
agent = CodeAgent(
|
| 57 |
model=model,
|
| 58 |
-
tools=[final_answer, image_generation_tool], ## add your tools here (don't remove final answer)
|
| 59 |
max_steps=6,
|
| 60 |
verbosity_level=1,
|
| 61 |
grammar=None,
|
|
|
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
+
from typing import Union
|
| 11 |
+
|
| 12 |
@tool
|
| 13 |
+
def unit_converter_tool(value:int, from_unit:str, to_unit:str)-> Union[int, float, str]:
|
| 14 |
+
"""Converts a value from one unit to another.
|
| 15 |
+
|
| 16 |
Args:
|
| 17 |
+
value (float or int): The numerical value to convert.
|
| 18 |
+
from_unit (str): The unit of the input value (e.g., "cm", "inch", "kg", "celsius").
|
| 19 |
+
to_unit (str): The unit to convert the value to (e.g., "meter", "feet", "lbs", "fahrenheit").
|
| 20 |
+
|
| 21 |
+
Returns:
|
| 22 |
+
float or int: The converted value.
|
| 23 |
+
str: "Conversion not supported." if the requested conversion is not available.
|
| 24 |
+
float or int: Returns the original value if from_unit and to_unit are the same.
|
| 25 |
+
|
| 26 |
+
Raises:
|
| 27 |
+
TypeError: If value is not a number (int or float).
|
| 28 |
+
|
| 29 |
+
Supported Conversions:
|
| 30 |
+
Length: cm, inch, meter, feet
|
| 31 |
+
Weight: kg, lbs, ton, quintal
|
| 32 |
+
Temperature: celsius, fahrenheit
|
| 33 |
+
|
| 34 |
"""
|
| 35 |
+
conversions = {
|
| 36 |
+
"cm_to_inch": lambda x: x * 0.393701,
|
| 37 |
+
"inch_to_cm": lambda x: x / 0.393701,
|
| 38 |
+
"cm_to_meter": lambda x: x / 100,
|
| 39 |
+
"meter_to_cm": lambda x: x * 100,
|
| 40 |
+
"cm_to_feet": lambda x: x * 0.0328084,
|
| 41 |
+
"feet_to_cm": lambda x: x / 0.0328084,
|
| 42 |
+
"inch_to_meter": lambda x: x * 0.0254,
|
| 43 |
+
"meter_to_inch": lambda x: x / 0.0254,
|
| 44 |
+
"inch_to_feet": lambda x: x * 0.0833333,
|
| 45 |
+
"feet_to_inch": lambda x: x / 0.0833333,
|
| 46 |
+
"meter_to_feet": lambda x: x * 3.28084,
|
| 47 |
+
"feet_to_meter": lambda x: x / 3.28084,
|
| 48 |
+
"kg_to_lbs": lambda x: x * 2.20462,
|
| 49 |
+
"lbs_to_kg": lambda x: x / 2.20462,
|
| 50 |
+
"kg_to_ton": lambda x: x * 0.001,
|
| 51 |
+
"ton_to_kg": lambda x: x / 0.001,
|
| 52 |
+
"kg_to_quintal": lambda x: x * 0.01,
|
| 53 |
+
"quintal_to_kg": lambda x: x / 0.01,
|
| 54 |
+
"ton_to_quintal": lambda x: x * 10,
|
| 55 |
+
"quintal_to_ton": lambda x: x / 10,
|
| 56 |
+
"celsius_to_fahrenheit": lambda x: (x * 9/5) + 32,
|
| 57 |
+
"fahrenheit_to_celsius": lambda x: (x - 32) * 5/9,
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
if not isinstance(value, (int, float)):
|
| 61 |
+
raise TypeError("Value must be a number (int or float).")
|
| 62 |
+
|
| 63 |
+
conversion_name = f"{from_unit}_to_{to_unit}"
|
| 64 |
+
|
| 65 |
+
# Handle cases where units might be the same:
|
| 66 |
+
if from_unit == to_unit:
|
| 67 |
+
return value
|
| 68 |
+
|
| 69 |
+
if conversion_name in conversions:
|
| 70 |
+
return conversions[conversion_name](value)
|
| 71 |
+
else:
|
| 72 |
+
return "Conversion not supported."
|
| 73 |
|
| 74 |
@tool
|
| 75 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 108 |
|
| 109 |
agent = CodeAgent(
|
| 110 |
model=model,
|
| 111 |
+
tools=[final_answer, image_generation_tool, unit_converter_tool], ## add your tools here (don't remove final answer)
|
| 112 |
max_steps=6,
|
| 113 |
verbosity_level=1,
|
| 114 |
grammar=None,
|