Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -50,12 +50,26 @@ custom_role_conversions=None,
|
|
| 50 |
# Import tool from Hub
|
| 51 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 52 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
with open("prompts.yaml", 'r') as stream:
|
| 54 |
prompt_templates = yaml.safe_load(stream)
|
| 55 |
|
| 56 |
agent = CodeAgent(
|
| 57 |
model=model,
|
| 58 |
-
tools=[final_answer, image_generation_tool
|
| 59 |
max_steps=6,
|
| 60 |
verbosity_level=1,
|
| 61 |
grammar=None,
|
|
|
|
| 50 |
# Import tool from Hub
|
| 51 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 52 |
|
| 53 |
+
@tool
|
| 54 |
+
def generate_image(prompt: str) -> str:
|
| 55 |
+
"""Generates an image based on a text prompt using a Hugging Face model.
|
| 56 |
+
Returns the path or object of the generated image.
|
| 57 |
+
|
| 58 |
+
Args:
|
| 59 |
+
prompt: A descriptive text prompt for the image (e.g., 'A cat on the beach').
|
| 60 |
+
"""
|
| 61 |
+
try:
|
| 62 |
+
# 调用远程工具
|
| 63 |
+
return image_generation_tool(prompt)
|
| 64 |
+
except Exception as e:
|
| 65 |
+
return f"Error generating image: {str(e)}"
|
| 66 |
+
|
| 67 |
with open("prompts.yaml", 'r') as stream:
|
| 68 |
prompt_templates = yaml.safe_load(stream)
|
| 69 |
|
| 70 |
agent = CodeAgent(
|
| 71 |
model=model,
|
| 72 |
+
tools=[final_answer, image_generation_tool], ## add your tools here (don't remove final answer)
|
| 73 |
max_steps=6,
|
| 74 |
verbosity_level=1,
|
| 75 |
grammar=None,
|