Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Hotfix] Fix save_image bug for generate_image_from_name in web/gradio/utils.py #410

Merged
merged 1 commit into from
Aug 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/agentscope/manager/_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def save_python_code(self) -> None:

def save_image(
self,
image: Union[str, np.ndarray, bytes],
image: Union[str, np.ndarray, bytes, Image.Image],
filename: Optional[str] = None,
) -> str:
"""Save image file locally, and return the local image path.
Expand Down Expand Up @@ -225,10 +225,13 @@ def save_image(
elif isinstance(image, bytes):
# save image via bytes
Image.open(io.BytesIO(image)).save(path_file)
elif isinstance(image, Image.Image):
# save image via PIL.Image.Image
image.save(path_file)
else:
raise ValueError(
f"Unsupported image type: {type(image)}"
"Must be str, np.ndarray, or bytes.",
f"Unsupported image type: {type(image)} Must be str, "
f"np.ndarray, bytes, or PIL.Image.Image.",
)

return path_file
Expand Down