Skip to content

Commit

Permalink
Adds missing components to gradio client serializing's component mapp…
Browse files Browse the repository at this point in the history
…ing (gradio-app#4167)

* add missing serialization

* format

* update release note format

* update release note format

* fix test
  • Loading branch information
abidlabs authored May 11, 2023
1 parent c4a884a commit e619875
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 17 deletions.
31 changes: 31 additions & 0 deletions client/python/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,36 @@
# Upcoming Release

# 0.2.4

## New Features:

No changes to highlight.

## Bug Fixes:
- Fixes missing serialization classes for several components: `Barplot`, `Lineplot`, `Scatterplot`, `AnnotatedImage`, `Interpretation` by [@abidlabs](https://github.com/freddyaboulton) in [PR 4167](https://github.com/gradio-app/gradio/pull/4167)

## Documentation Changes:

No changes to highlight.

## Testing and Infrastructure Changes:

No changes to highlight.

## Breaking Changes:

No changes to highlight.

## Full Changelog:

No changes to highlight.

## Contributors Shoutout:

No changes to highlight.

# 0.2.3

## New Features:

No changes to highlight.
Expand Down
5 changes: 5 additions & 0 deletions client/python/gradio_client/serializing.py
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,12 @@ def deserialize(
"chatbot": JSONSerializable,
"model3d": FileSerializable,
"plot": JSONSerializable,
"barplot": JSONSerializable,
"lineplot": JSONSerializable,
"scatterplot": JSONSerializable,
"markdown": StringSerializable,
"dataset": StringSerializable,
"code": StringSerializable,
"interpretation": SimpleSerializable,
"annotatedimage": JSONSerializable,
}
2 changes: 1 addition & 1 deletion client/python/gradio_client/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.2.3
0.2.4
22 changes: 22 additions & 0 deletions client/python/test/conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import inspect
import random
import time

Expand Down Expand Up @@ -178,3 +179,24 @@ def file_io_demo():
)

return demo


@pytest.fixture
def all_components():
classes_to_check = gr.components.Component.__subclasses__()
subclasses = []

while classes_to_check:
subclass = classes_to_check.pop()
children = subclass.__subclasses__()

if children:
classes_to_check.extend(children)
if (
"value" in inspect.signature(subclass).parameters
and subclass != gr.components.IOComponent
and not getattr(subclass, "is_template", False)
):
subclasses.append(subclass)

return subclasses
8 changes: 7 additions & 1 deletion client/python/test/test_serializing.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,18 @@ def test_duplicate(serializer_class):

def test_check_component_fallback_serializers():
for component_name, class_type in COMPONENT_MAPPING.items():
if component_name == "dataset": # cannot be instantiated without parameters
# skip components that cannot be instantiated without parameters
if component_name in ["dataset", "interpretation"]:
continue
component = components.get_component_instance(component_name)
assert isinstance(component, class_type)


def test_all_components_in_component_mapping(all_components):
for component in all_components:
assert component.__name__.lower() in COMPONENT_MAPPING


def test_file_serializing():

try:
Expand Down
12 changes: 1 addition & 11 deletions scripts/format_release_notes.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,12 @@
## Bug Fixes:
No changes to highlight.
## Documentation Changes:
No changes to highlight.
## Testing and Infrastructure Changes:
## Other Changes:
No changes to highlight.
## Breaking Changes:
No changes to highlight.
## Full Changelog:
No changes to highlight.
## Contributors Shoutout:
No changes to highlight.
"""


Expand Down
7 changes: 3 additions & 4 deletions test/test_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -1474,10 +1474,9 @@ def test_component_functions(self):

class TestNames:
# This test ensures that `components.get_component_instance()` works correctly when instantiating from components
def test_no_duplicate_uncased_names(self):
subclasses = gr.components.Component.__subclasses__()
unique_subclasses_uncased = {s.__name__.lower() for s in subclasses}
assert len(subclasses) == len(unique_subclasses_uncased)
def test_no_duplicate_uncased_names(self, io_components):
unique_subclasses_uncased = {s.__name__.lower() for s in io_components}
assert len(io_components) == len(unique_subclasses_uncased)


class TestLabel:
Expand Down

0 comments on commit e619875

Please sign in to comment.