diff --git a/.changeset/ripe-ears-tease.md b/.changeset/ripe-ears-tease.md new file mode 100644 index 0000000000000..e43e3488e6ace --- /dev/null +++ b/.changeset/ripe-ears-tease.md @@ -0,0 +1,5 @@ +--- +"gradio": patch +--- + +fix:Add support for `numpy~=2.0` diff --git a/gradio/processing_utils.py b/gradio/processing_utils.py index 3c0d4b7bd5c86..5b658842ee12c 100644 --- a/gradio/processing_utils.py +++ b/gradio/processing_utils.py @@ -104,6 +104,7 @@ async def handle_async_request( if TYPE_CHECKING: from gradio.blocks import Block + ######################### # GENERAL ######################### @@ -660,14 +661,17 @@ def _convert(image, dtype, force_copy=False, uniform=False): dtype_range = { bool: (False, True), np.bool_: (False, True), - np.bool8: (False, True), # type: ignore float: (-1, 1), - np.float_: (-1, 1), np.float16: (-1, 1), np.float32: (-1, 1), np.float64: (-1, 1), } + if hasattr(np, "float_"): + dtype_range[np.float_] = dtype_range[float] # type: ignore + if hasattr(np, "bool8"): + dtype_range[np.bool8] = dtype_range[np.bool_] # type: ignore + def _dtype_itemsize(itemsize, *dtypes): """Return first of `dtypes` with itemsize greater than `itemsize` Parameters @@ -786,7 +790,12 @@ def _scale(a, n, m, copy=True): # is a subclass of that type (e.g. `np.floating` will allow # `float32` and `float64` arrays through) - if np.issubdtype(dtype_in, np.obj2sctype(dtype)): + if hasattr(np, "obj2sctype"): + is_subdtype = np.issubdtype(dtype_in, np.obj2sctype(dtype)) + else: + is_subdtype = np.issubdtype(dtype_in, dtypeobj_out.type) + + if is_subdtype: if force_copy: image = image.copy() return image diff --git a/requirements.txt b/requirements.txt index 777c6c5fc90a0..2f6c6d2c746f6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,7 +9,7 @@ importlib_resources>=1.3,<7.0 Jinja2<4.0 markupsafe~=2.0 matplotlib~=3.0 -numpy~=1.0 +numpy>=1.0,<3.0 orjson~=3.0 packaging pandas>=1.0,<3.0