Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,6 +8,7 @@ import os, io
|
|
| 8 |
from PIL import Image
|
| 9 |
from smolagents.agent_types import AgentImage
|
| 10 |
from smolagents import tool
|
|
|
|
| 11 |
|
| 12 |
|
| 13 |
from Gradio_UI import GradioUI
|
|
@@ -61,6 +62,20 @@ def text_to_image(prompt: str) -> AgentImage:
|
|
| 61 |
img = Image.open(io.BytesIO(resp.content)).convert("RGB")
|
| 62 |
return AgentImage(img)
|
| 63 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
final_answer = FinalAnswerTool()
|
| 65 |
|
| 66 |
# If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
|
|
@@ -82,7 +97,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 82 |
|
| 83 |
agent = CodeAgent(
|
| 84 |
model=model,
|
| 85 |
-
tools=[final_answer, DuckDuckGoSearchTool(), image_generation_tool, get_current_time_in_timezone, text_to_image ], ## add your tools here (don't remove final answer)
|
| 86 |
max_steps=6,
|
| 87 |
verbosity_level=1,
|
| 88 |
grammar=None,
|
|
|
|
| 8 |
from PIL import Image
|
| 9 |
from smolagents.agent_types import AgentImage
|
| 10 |
from smolagents import tool
|
| 11 |
+
from PIL import Image as PILImage
|
| 12 |
|
| 13 |
|
| 14 |
from Gradio_UI import GradioUI
|
|
|
|
| 62 |
img = Image.open(io.BytesIO(resp.content)).convert("RGB")
|
| 63 |
return AgentImage(img)
|
| 64 |
|
| 65 |
+
@tool
|
| 66 |
+
def generate_image(prompt: str) -> AgentImage:
|
| 67 |
+
"""Generate an image and return AgentImage for UI rendering.
|
| 68 |
+
Args:
|
| 69 |
+
prompt: The image description.
|
| 70 |
+
"""
|
| 71 |
+
res = image_generator(prompt=prompt)
|
| 72 |
+
if isinstance(res, PILImage.Image):
|
| 73 |
+
return AgentImage(res)
|
| 74 |
+
# 如果 hub 工具未来直接返回 AgentImage,就直接透传
|
| 75 |
+
if hasattr(res, "image"):
|
| 76 |
+
return res
|
| 77 |
+
raise RuntimeError(f"Unexpected image type from image_generator: {type(res)}")
|
| 78 |
+
|
| 79 |
final_answer = FinalAnswerTool()
|
| 80 |
|
| 81 |
# If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
|
|
|
|
| 97 |
|
| 98 |
agent = CodeAgent(
|
| 99 |
model=model,
|
| 100 |
+
tools=[final_answer, DuckDuckGoSearchTool(), image_generation_tool, get_current_time_in_timezone, text_to_image , generate_image ], ## add your tools here (don't remove final answer)
|
| 101 |
max_steps=6,
|
| 102 |
verbosity_level=1,
|
| 103 |
grammar=None,
|