Repository: huggingface/diffusers
File: src/diffusers/utils/testing_utils.py (Python)

Code before:
            return Path(local_path, arry.split("/")[-5], arry.split("/")[-2], arry.split("/")[-1]).as_posix()
        elif arry.startswith("http://") or arry.startswith("https://"):
            response = requests.get(arry, timeout=DIFFUSERS_REQUEST_TIMEOUT)
            response.raise_for_status()
            arry = np.load(BytesIO(response.content))
        elif os.path.isfile(arry):
            arry = np.load(arry)
        else:
            raise ValueError(
                f"Incorrect path or url, URLs must start with `http://` or `https://`, and {arry} is not a valid path"
            )
    elif isinstance(arry, np.ndarray):
        pass
    else:
        raise ValueError(
            "Incorrect format used for numpy ndarray. Should be an url linking to an image, a local path, or a"
            " ndarray."
        )

    return arry


def load_pt(url: str, map_location: Optional[str] = None):
    response = requests.get(url, timeout=DIFFUSERS_REQUEST_TIMEOUT)
    response.raise_for_status()
    arry = torch.load(BytesIO(response.content), map_location=map_location, weights_only=False)
    return arry


def load_image(image: Union[str, PIL.Image.Image]) -> PIL.Image.Image:
    """
    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.
    """
    if isinstance(image, str):
        if image.startswith("http://") or image.startswith("https://"):
            image = PIL.Image.open(requests.get(image, stream=True, timeout=DIFFUSERS_REQUEST_TIMEOUT).raw)
        elif os.path.isfile(image):
            image = PIL.Image.open(image)
        else:
            raise ValueError(
                f"Incorrect path or url, URLs must start with `http://` or `https://`, and {image} is not a valid path"
            )
    elif isinstance(image, PIL.Image.Image):
        image = image

Review comment (performance):
1. `weights_only` default value changed from `False` to `True` from PyTorch 2.6, so set explicitly to `False` here, otherwise `tests/pipelines/text_to_video_synthesis/test_text_to_video_zero.py::TextToVideoZeroPipelineSlowTests::test_full_model
` will raise error
2. set `map_location` default as None which aligns w. `torch.load`, otherwise  `tests/pipelines/text_to_video_synthesis/test_text_to_video_zero.py::TextToVideoZeroPipelineSlowTests::test_full_model
` will raise error

Code after:
    major, minor = sys_info.major, sys_info.minor
    return major, minor


def load_numpy(arry: Union[str, np.ndarray], local_path: Optional[str] = None) -> np.ndarray:
    if isinstance(arry, str):
        if local_path is not None:
            # local_path can be passed to correct images of tests
            return Path(local_path, arry.split("/")[-5], arry.split("/")[-2], arry.split("/")[-1]).as_posix()
        elif arry.startswith("http://") or arry.startswith("https://"):
            response = requests.get(arry, timeout=DIFFUSERS_REQUEST_TIMEOUT)
            response.raise_for_status()
            arry = np.load(BytesIO(response.content))
        elif os.path.isfile(arry):
            arry = np.load(arry)
        else:
            raise ValueError(
                f"Incorrect path or url, URLs must start with `http://` or `https://`, and {arry} is not a valid path"
            )
    elif isinstance(arry, np.ndarray):
        pass
    else:
        raise ValueError(
            "Incorrect format used for numpy ndarray. Should be an url linking to an image, a local path, or a"
            " ndarray."
        )

    return arry


def load_pt(url: str, map_location: Optional[str] = None, weights_only: Optional[bool] = True):
    response = requests.get(url, timeout=DIFFUSERS_REQUEST_TIMEOUT)
    response.raise_for_status()
    arry = torch.load(BytesIO(response.content), map_location=map_location, weights_only=weights_only)
    return arry


def load_image(image: Union[str, PIL.Image.Image]) -> PIL.Image.Image:
    """
    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.
    """
    if isinstance(image, str):
        if image.startswith("http://") or image.startswith("https://"):
            image = PIL.Image.open(requests.get(image, stream=True, timeout=DIFFUSERS_REQUEST_TIMEOUT).raw)