Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for numpy~=2.0 #8440

Merged
merged 10 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/ripe-ears-tease.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"gradio": patch
---

fix:Add support for `numpy~=2.0`
15 changes: 12 additions & 3 deletions gradio/processing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ async def handle_async_request(
if TYPE_CHECKING:
from gradio.blocks import Block


#########################
# GENERAL
#########################
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down