Skip to content

Commit

Permalink
Remove flag_dir from read_from_flag() (#7059)
Browse files Browse the repository at this point in the history
* Remove flag_dir from read_from_flag()

* fix

* remove unnecessary ruff exception

---------

Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
  • Loading branch information
akx and abidlabs committed Feb 1, 2024
1 parent 59c5081 commit 7ea8336
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 19 deletions.
5 changes: 5 additions & 0 deletions .changeset/slow-bikes-thank.md
@@ -0,0 +1,5 @@
---
"gradio": minor
---

feat:Remove flag_dir from read_from_flag()
12 changes: 2 additions & 10 deletions gradio/components/base.py
Expand Up @@ -99,11 +99,7 @@ def flag(self, payload: Any | GradioDataModel, flag_dir: str | Path = "") -> str
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.
"""
Expand Down Expand Up @@ -286,11 +282,7 @@ def flag(self, payload: Any, flag_dir: str | Path = "") -> str:
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.
"""
Expand Down
2 changes: 1 addition & 1 deletion gradio/components/json_component.py
Expand Up @@ -100,7 +100,7 @@ def flag(
) -> 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]:
Expand Down
2 changes: 1 addition & 1 deletion gradio/components/state.py
Expand Up @@ -28,7 +28,7 @@ class State(Component):
def __init__(
self,
value: Any = None,
render: bool = True, # noqa: ARG002
render: bool = True,
):
"""
Parameters:
Expand Down
7 changes: 1 addition & 6 deletions gradio/helpers.py
Expand Up @@ -423,12 +423,7 @@ def load_from_cache(self, example_id: int) -> list[Any]:
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


Expand Down
1 change: 0 additions & 1 deletion guides/05_custom-components/04_backend.md
Expand Up @@ -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.
Expand Down

0 comments on commit 7ea8336

Please sign in to comment.