Skip to content

Commit

Permalink
Catch ValueError, KeyError when saving PIL Image (#6462)
Browse files Browse the repository at this point in the history
* Add code

* add changeset

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
  • Loading branch information
freddyaboulton and gradio-pr-bot committed Nov 17, 2023
1 parent 3953a14 commit 2761b6d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/nice-dolls-rescue.md
@@ -0,0 +1,5 @@
---
"gradio": minor
---

feat:Catch ValueError, KeyError when saving PIL Image
4 changes: 2 additions & 2 deletions gradio/image_utils.py
Expand Up @@ -32,7 +32,7 @@ def format_image(
im, cache_dir=cache_dir, name=name, format=fmt or format # type: ignore
)
# Catch error if format is not supported by PIL
except KeyError:
except (KeyError, ValueError):
path = processing_utils.save_pil_to_cache(
im, cache_dir=cache_dir, name=name, format="png" # type: ignore
)
Expand All @@ -57,7 +57,7 @@ def save_image(y: np.ndarray | _Image.Image | str | Path, cache_dir: str):
y, cache_dir=cache_dir, format=fmt # type: ignore
)
# Catch error if format is not supported by PIL
except KeyError:
except (KeyError, ValueError):
path = processing_utils.save_pil_to_cache(
y, cache_dir=cache_dir, format="png"
)
Expand Down

0 comments on commit 2761b6d

Please sign in to comment.