Skip to content

Commit

Permalink
fix save_image bug for generate_image_from_name in gradio/utils.py (#410
Browse files Browse the repository at this point in the history
)
  • Loading branch information
qbc2016 authored Aug 19, 2024
1 parent 01530ee commit 3ed447b
Showing 1 changed file with 6 additions and 3 deletions.
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

0 comments on commit 3ed447b

Please sign in to comment.