Update app.py
Browse files
app.py
CHANGED
|
@@ -7,6 +7,31 @@ from tools.final_answer import FinalAnswerTool
|
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
|
@@ -48,15 +73,14 @@ custom_role_conversions=None,
|
|
| 48 |
)
|
| 49 |
|
| 50 |
|
| 51 |
-
|
| 52 |
-
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 53 |
|
| 54 |
with open("prompts.yaml", 'r') as stream:
|
| 55 |
prompt_templates = yaml.safe_load(stream)
|
| 56 |
|
| 57 |
agent = CodeAgent(
|
| 58 |
model=model,
|
| 59 |
-
tools=[final_answer,get_current_time_in_timezone], ## add your tools here (don't remove final answer)
|
| 60 |
max_steps=6,
|
| 61 |
verbosity_level=1,
|
| 62 |
grammar=None,
|
|
|
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
+
|
| 11 |
+
# Import tool from Hub
|
| 12 |
+
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 16 |
+
|
| 17 |
+
@tool
|
| 18 |
+
def generate_image_tool(prompt: str) -> str:
|
| 19 |
+
"""Generates an image from text using the image generation tool.
|
| 20 |
+
|
| 21 |
+
Args:
|
| 22 |
+
prompt: A description of the image to generate.
|
| 23 |
+
|
| 24 |
+
Returns:
|
| 25 |
+
The generated image URL or path.
|
| 26 |
+
"""
|
| 27 |
+
try:
|
| 28 |
+
return image_generation_tool(prompt)
|
| 29 |
+
except Exception as e:
|
| 30 |
+
return f"Error generating image: {str(e)}"
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
|
| 35 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 36 |
@tool
|
| 37 |
def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
|
|
|
|
| 73 |
)
|
| 74 |
|
| 75 |
|
| 76 |
+
|
|
|
|
| 77 |
|
| 78 |
with open("prompts.yaml", 'r') as stream:
|
| 79 |
prompt_templates = yaml.safe_load(stream)
|
| 80 |
|
| 81 |
agent = CodeAgent(
|
| 82 |
model=model,
|
| 83 |
+
tools=[final_answer,my_custom_tool,get_current_time_in_timezone,generate_image_tool], ## add your tools here (don't remove final answer)
|
| 84 |
max_steps=6,
|
| 85 |
verbosity_level=1,
|
| 86 |
grammar=None,
|