2
0
mirror of https://github.com/gradio-app/gradio.git synced 2025-04-12 12:40:29 +08:00

Remove flag_dir from read_from_flag() ()

* Remove flag_dir from read_from_flag()

* fix

* remove unnecessary ruff exception

---------

Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
This commit is contained in:
Aarni Koskela 2024-02-01 22:24:26 +02:00 committed by GitHub
parent 59c50811fb
commit 7ea8336709
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 10 additions and 19 deletions
.changeset
gradio
guides/05_custom-components

@ -0,0 +1,5 @@
---
"gradio": minor
---
feat:Remove flag_dir from read_from_flag()

@ -99,11 +99,7 @@ class ComponentBase(ABC, metaclass=ComponentMeta):
pass
@abstractmethod
def read_from_flag(
self,
payload: Any,
flag_dir: str | Path | None = None,
) -> GradioDataModel | Any:
def read_from_flag(self, payload: Any) -> GradioDataModel | Any:
"""
Convert the data from the csv or jsonl file into the component state.
"""
@ -286,11 +282,7 @@ class Component(ComponentBase, Block):
return payload.copy_to_dir(flag_dir).model_dump_json()
return payload
def read_from_flag(
self,
payload: Any,
flag_dir: str | Path | None = None, # noqa: ARG002
):
def read_from_flag(self, payload: Any):
"""
Convert the data from the csv or jsonl file into the component state.
"""

@ -100,7 +100,7 @@ class JSON(Component):
) -> str:
return json.dumps(payload)
def read_from_flag(self, payload: Any, flag_dir: str | Path | None = None): # noqa: ARG002
def read_from_flag(self, payload: Any):
return json.loads(payload)
def api_info(self) -> dict[str, Any]:

@ -28,7 +28,7 @@ class State(Component):
def __init__(
self,
value: Any = None,
render: bool = True, # noqa: ARG002
render: bool = True,
):
"""
Parameters:

@ -423,12 +423,7 @@ class Examples:
assert utils.is_update(value_as_dict)
output.append(value_as_dict)
except (ValueError, TypeError, SyntaxError, AssertionError):
output.append(
component.read_from_flag(
value_to_use,
self.cached_folder,
)
)
output.append(component.read_from_flag(value_to_use))
return output

@ -126,7 +126,6 @@ The `data_model` in the following section.
def read_from_flag(
self,
x: Any,
flag_dir: str | Path | None = None,
) -> GradioDataModel | Any:
"""
Convert the data from the csv or jsonl file into the component state.