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

fix dataset update #8581

Merged
merged 13 commits into from
Jun 19, 2024
6 changes: 3 additions & 3 deletions gradio/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1723,12 +1723,12 @@ async def postprocess_data(
) from err

if block.stateful:
if not utils.is_update(predictions[i]):
if not utils.is_prop_update(predictions[i]):
state[block._id] = predictions[i]
output.append(None)
else:
prediction_value = predictions[i]
if utils.is_update(
if utils.is_prop_update(
prediction_value
): # if update is passed directly (deprecated), remove Nones
prediction_value = utils.delete_none(
Expand All @@ -1738,7 +1738,7 @@ async def postprocess_data(
if isinstance(prediction_value, Block):
prediction_value = prediction_value.constructor_args.copy()
prediction_value["__type__"] = "update"
if utils.is_update(prediction_value):
if utils.is_prop_update(prediction_value):
kwargs = state[block._id].constructor_args.copy()
kwargs.update(prediction_value)
kwargs.pop("value", None)
Expand Down
4 changes: 2 additions & 2 deletions gradio/components/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def __init__(
self,
*,
label: str | None = None,
components: list[Component] | list[str],
components: list[Component] | list[str] | None = None,
component_props: list[dict[str, Any]] | None = None,
samples: list[list[Any]] | None = None,
headers: list[str] | None = None,
Expand Down Expand Up @@ -70,7 +70,7 @@ def __init__(
self.container = container
self.scale = scale
self.min_width = min_width
self._components = [get_component_instance(c) for c in components]
self._components = [get_component_instance(c) for c in components or []]
if component_props is None:
self.component_props = [
component.recover_kwargs(
Expand Down
2 changes: 1 addition & 1 deletion gradio/flagging.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def flag(
) / client_utils.strip_invalid_filename_characters(
getattr(component, "label", None) or f"component {idx}"
)
if utils.is_update(sample):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a refactor for clarity

if utils.is_prop_update(sample):
csv_data.append(str(sample))
else:
data = (
Expand Down
2 changes: 1 addition & 1 deletion gradio/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ def load_from_cache(self, example_id: int) -> list[Any]:
component, components.File
):
value_to_use = value_as_dict
if not utils.is_update(value_as_dict):
if not utils.is_prop_update(value_as_dict):
raise TypeError("value wasn't an update") # caught below
output.append(value_as_dict)
except (ValueError, TypeError, SyntaxError):
Expand Down
2 changes: 1 addition & 1 deletion gradio/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ def validate_url(possible_url: str) -> bool:
return False


def is_update(val):
def is_prop_update(val):
return isinstance(val, dict) and "update" in val.get("__type__", "")


Expand Down
5 changes: 3 additions & 2 deletions js/dataset/Index.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
>;
export let label = "Examples";
export let headers: string[];
export let samples: any[][];
export let samples: any[][] | null = null;
export let elem_id = "";
export let elem_classes: string[] = [];
export let visible = true;
Expand All @@ -34,7 +34,7 @@
: `${root}/file=`;
let page = 0;
$: gallery = components.length < 2;
let paginate = samples.length > samples_per_page;
let paginate = samples ? samples.length > samples_per_page : false;

let selected_samples: any[][];
let page_count: number;
Expand All @@ -51,6 +51,7 @@
}

$: {
samples = samples || [];
paginate = samples.length > samples_per_page;
if (paginate) {
visible_pages = [];
Expand Down