Spaces:
Sleeping
Sleeping
Update app.py
Browse filesadd implementation de my_custom_tool
app.py
CHANGED
|
@@ -10,13 +10,23 @@ from Gradio_UI import GradioUI
|
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
@tool
|
| 12 |
def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
|
| 13 |
-
|
| 14 |
-
"""A tool that does nothing yet
|
| 15 |
Args:
|
| 16 |
-
arg1: the
|
| 17 |
-
arg2: the
|
| 18 |
"""
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
@@ -78,7 +88,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 78 |
|
| 79 |
agent = CodeAgent(
|
| 80 |
model=model,
|
| 81 |
-
tools=[final_answer, get_weather], ## add your tools here (don't remove final answer)
|
| 82 |
max_steps=6,
|
| 83 |
verbosity_level=1,
|
| 84 |
grammar=None,
|
|
|
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
@tool
|
| 12 |
def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
|
| 13 |
+
"""A tool that generates text or an image based on the provided arguments.
|
|
|
|
| 14 |
Args:
|
| 15 |
+
arg1: A string input to guide the generation.
|
| 16 |
+
arg2: An integer input to specify the type of generation (1 for text, 2 for image).
|
| 17 |
"""
|
| 18 |
+
if arg2 == 1:
|
| 19 |
+
# Generate text using LLM
|
| 20 |
+
prompt = f"Generate a detailed description based on the following input: {arg1}"
|
| 21 |
+
response = model.generate(prompt)
|
| 22 |
+
return response['choices'][0]['text']
|
| 23 |
+
elif arg2 == 2:
|
| 24 |
+
# Generate image using image generation tool
|
| 25 |
+
prompt = f"Generate an image based on the following input: {arg1}"
|
| 26 |
+
image_url = image_generation_tool(prompt)
|
| 27 |
+
return f"Image generated: {image_url}"
|
| 28 |
+
else:
|
| 29 |
+
return "Invalid argument for arg2. Use 1 for text generation and 2 for image generation."
|
| 30 |
|
| 31 |
@tool
|
| 32 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 88 |
|
| 89 |
agent = CodeAgent(
|
| 90 |
model=model,
|
| 91 |
+
tools=[final_answer, get_weather, my_custom_tool], ## add your tools here (don't remove final answer)
|
| 92 |
max_steps=6,
|
| 93 |
verbosity_level=1,
|
| 94 |
grammar=None,
|