mirror of
https://github.com/gradio-app/gradio.git
synced 2024-11-21 01:01:05 +08:00
Several fixes to gr.load
(#7706)
* stash pop * add changeset * add changeset * state fix * add changeset * push * ignore * format --------- Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
This commit is contained in:
parent
95c6bc897b
commit
bc61ff6b16
6
.changeset/sour-lizards-follow.md
Normal file
6
.changeset/sour-lizards-follow.md
Normal file
@ -0,0 +1,6 @@
|
||||
---
|
||||
"gradio": patch
|
||||
"gradio_client": patch
|
||||
---
|
||||
|
||||
fix:Several fixes to `gr.load`
|
@ -1115,7 +1115,13 @@ class Endpoint:
|
||||
return tuple(data)
|
||||
|
||||
def reduce_singleton_output(self, *data) -> Any:
|
||||
if len([oct for oct in self.output_component_types if not oct.skip]) == 1:
|
||||
if self.client._skip_components:
|
||||
effective_output_components = [
|
||||
o for o in self.output_component_types if not o.skip
|
||||
]
|
||||
else:
|
||||
effective_output_components = self.output_component_types
|
||||
if len(effective_output_components) == 1:
|
||||
return data[0]
|
||||
else:
|
||||
return data
|
||||
|
@ -272,7 +272,9 @@ class Block:
|
||||
|
||||
return temp_file_path
|
||||
|
||||
def serve_static_file(self, url_or_file_path: str | Path | None) -> dict | None:
|
||||
def serve_static_file(
|
||||
self, url_or_file_path: str | Path | dict | None
|
||||
) -> dict | None:
|
||||
"""If a file is a local file, moves it to the block's cache directory and returns
|
||||
a FileData-type dictionary corresponding to the file. If the file is a URL, returns a
|
||||
FileData-type dictionary corresponding to the URL. This ensures that the file is
|
||||
@ -281,12 +283,14 @@ class Block:
|
||||
Examples:
|
||||
>>> block.serve_static_file("https://gradio.app/logo.png") -> {"path": "https://gradio.app/logo.png", "url": "https://gradio.app/logo.png"}
|
||||
>>> block.serve_static_file("logo.png") -> {"path": "logo.png", "url": "/file=logo.png"}
|
||||
>>> block.serve_static_file({"path": "logo.png", "url": "/file=logo.png"}) -> {"path": "logo.png", "url": "/file=logo.png"}
|
||||
"""
|
||||
if url_or_file_path is None:
|
||||
return None
|
||||
if isinstance(url_or_file_path, dict):
|
||||
return url_or_file_path
|
||||
if isinstance(url_or_file_path, Path):
|
||||
url_or_file_path = str(url_or_file_path)
|
||||
|
||||
if client_utils.is_http_url_like(url_or_file_path):
|
||||
return FileData(path=url_or_file_path, url=url_or_file_path).model_dump()
|
||||
else:
|
||||
|
@ -27,6 +27,7 @@ class Dataset(Component):
|
||||
*,
|
||||
label: str | None = None,
|
||||
components: list[Component] | list[str],
|
||||
component_props: list[dict[str, Any]] | None = None,
|
||||
samples: list[list[Any]] | None = None,
|
||||
headers: list[str] | None = None,
|
||||
type: Literal["values", "index"] = "values",
|
||||
@ -67,13 +68,16 @@ class Dataset(Component):
|
||||
self.scale = scale
|
||||
self.min_width = min_width
|
||||
self._components = [get_component_instance(c) for c in components]
|
||||
self.component_props = [
|
||||
component.recover_kwargs(
|
||||
component.get_config(),
|
||||
["value"],
|
||||
)
|
||||
for component in self._components
|
||||
]
|
||||
if component_props is None:
|
||||
self.component_props = [
|
||||
component.recover_kwargs(
|
||||
component.get_config(),
|
||||
["value"],
|
||||
)
|
||||
for component in self._components
|
||||
]
|
||||
else:
|
||||
self.component_props = component_props
|
||||
|
||||
# Narrow type to Component
|
||||
if not all(isinstance(c, Component) for c in self._components):
|
||||
|
@ -258,10 +258,11 @@ class Examples:
|
||||
processed_example = self.non_none_processed_examples[example_id]
|
||||
if len(self.inputs_with_examples) == 1:
|
||||
return update(
|
||||
value=processed_example[0], **self.dataset.component_props[0]
|
||||
value=processed_example[0],
|
||||
**self.dataset.component_props[0], # type: ignore
|
||||
)
|
||||
return [
|
||||
update(value=processed_example[i], **self.dataset.component_props[i])
|
||||
update(value=processed_example[i], **self.dataset.component_props[i]) # type: ignore
|
||||
for i in range(len(self.inputs_with_examples))
|
||||
]
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user