Spaces:
Runtime error
Runtime error
added a secret to the space with HF_TOKEN as the name and include the image tool again
Browse files
app.py
CHANGED
@@ -5,11 +5,28 @@ import pytz
|
|
5 |
import yaml
|
6 |
from tools.final_answer import FinalAnswerTool
|
7 |
from PIL import Image
|
8 |
-
from tools.visit_webpage import VisitWebpageTool
|
9 |
-
from tools.code_explainer import CodeExplainerTool
|
10 |
|
11 |
from Gradio_UI import GradioUI
|
12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
@tool
|
14 |
def get_current_time_in_timezone(timezone: str) -> str:
|
15 |
"""A tool that fetches the current local time in a specified timezone.
|
@@ -39,10 +56,6 @@ model = HfApiModel(
|
|
39 |
custom_role_conversions=None,
|
40 |
)
|
41 |
|
42 |
-
visit_webpage = VisitWebpageTool()
|
43 |
-
code_explainer = CodeExplainerTool()
|
44 |
-
|
45 |
-
|
46 |
# Import tool from Hub
|
47 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
48 |
|
@@ -51,7 +64,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
51 |
|
52 |
agent = CodeAgent(
|
53 |
model=model,
|
54 |
-
tools=[final_answer,
|
55 |
max_steps=6,
|
56 |
verbosity_level=1,
|
57 |
grammar=None,
|
|
|
5 |
import yaml
|
6 |
from tools.final_answer import FinalAnswerTool
|
7 |
from PIL import Image
|
|
|
|
|
8 |
|
9 |
from Gradio_UI import GradioUI
|
10 |
|
11 |
+
@tool
|
12 |
+
def image_generator(character:str, sceneDescription:str)-> Image: #it's important to specify the return type
|
13 |
+
#Keep this format for the description / args / args description but feel free to modify the tool
|
14 |
+
"""A tool that returns an image base on a character and a scene setting
|
15 |
+
Args:
|
16 |
+
character: the character
|
17 |
+
sceneDescription: the description of the scene
|
18 |
+
|
19 |
+
Returns:
|
20 |
+
Image: The generated image of the character in the specified scene.
|
21 |
+
"""
|
22 |
+
try:
|
23 |
+
# call the image_generation_tool tool with a text prompt
|
24 |
+
image = image_generation_tool(f"{character} in {sceneDescription}")
|
25 |
+
img = Image.open(BytesIO(image_response.content))
|
26 |
+
return img
|
27 |
+
except Exception as e:
|
28 |
+
return f"Error fetching image for given inputs: {str(e)}"
|
29 |
+
|
30 |
@tool
|
31 |
def get_current_time_in_timezone(timezone: str) -> str:
|
32 |
"""A tool that fetches the current local time in a specified timezone.
|
|
|
56 |
custom_role_conversions=None,
|
57 |
)
|
58 |
|
|
|
|
|
|
|
|
|
59 |
# Import tool from Hub
|
60 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
61 |
|
|
|
64 |
|
65 |
agent = CodeAgent(
|
66 |
model=model,
|
67 |
+
tools=[final_answer, image_generator, visit_webpage, code_explainer], ## add your tools here (don't remove final answer)
|
68 |
max_steps=6,
|
69 |
verbosity_level=1,
|
70 |
grammar=None,
|