Loads `image` to a PIL Image. Args: image (`str` or `PIL.Image.Image`): The image to convert to the PIL Image format. Returns: `PIL.Image.Image`: A PIL Image.
(image: str | PIL.Image.Image)
| 713 | |
| 714 | |
| 715 | def load_image(image: str | PIL.Image.Image) -> PIL.Image.Image: |
| 716 | """ |
| 717 | Loads `image` to a PIL Image. |
| 718 | |
| 719 | Args: |
| 720 | image (`str` or `PIL.Image.Image`): |
| 721 | The image to convert to the PIL Image format. |
| 722 | Returns: |
| 723 | `PIL.Image.Image`: |
| 724 | A PIL Image. |
| 725 | """ |
| 726 | if isinstance(image, str): |
| 727 | if image.startswith("http://") or image.startswith("https://"): |
| 728 | image = PIL.Image.open(requests.get(image, stream=True, timeout=DIFFUSERS_REQUEST_TIMEOUT).raw) |
| 729 | elif os.path.isfile(image): |
| 730 | image = PIL.Image.open(image) |
| 731 | else: |
| 732 | raise ValueError( |
| 733 | f"Incorrect path or url, URLs must start with `http://` or `https://`, and {image} is not a valid path" |
| 734 | ) |
| 735 | elif isinstance(image, PIL.Image.Image): |
| 736 | image = image |
| 737 | else: |
| 738 | raise ValueError( |
| 739 | "Incorrect format used for image. Should be an url linking to an image, a local path, or a PIL image." |
| 740 | ) |
| 741 | image = PIL.ImageOps.exif_transpose(image) |
| 742 | image = image.convert("RGB") |
| 743 | return image |
| 744 | |
| 745 | |
| 746 | def preprocess_image(image: PIL.Image, batch_size: int): |
nothing calls this directly
no test coverage detected
searching dependent graphs…