Add docs for HF Json saver (#3604)

* Add docs for flagging

* Fix params

* CHANGELOG

---------

Co-authored-by: freddyaboulton <alfonsoboulton@gmail.com>
This commit is contained in:
Omar Sanseviero 2023-03-27 16:40:07 +02:00 committed by GitHub
parent c9b8a0c484
commit cecd5a2526
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 13 deletions

View File

@ -17,9 +17,9 @@
## Documentation Changes:
- Makes some fixes to the Theme Guide related to naming of variables, by [@abidlabs](https://github.com/abidlabs) in [PR 3561](https://github.com/gradio-app/gradio/pull/3561)
- Documented `HuggingFaceDatasetJSONSaver` by [@osanseviero](https://github.com/osanseviero) in [PR 3604](https://github.com/gradio-app/gradio/pull/3604)
- Makes some additions to documentation of `Audio` and `State` components, and fixes the `pictionary` demo by [@abidlabs](https://github.com/abidlabs) in [PR 3611](https://github.com/gradio-app/gradio/pull/3611)
## Testing and Infrastructure Changes:
- Removed heavily-mocked tests related to comet_ml, wandb, and mlflow as they added a significant amount of test dependencies that prevented installation of test dependencies on Windows environemnts. By [@abidlabs](https://github.com/abidlabs) in [PR 3608](https://github.com/gradio-app/gradio/pull/3608)

View File

@ -365,14 +365,24 @@ class HuggingFaceDatasetSaver(FlaggingCallback):
return line_count
@document()
class HuggingFaceDatasetJSONSaver(FlaggingCallback):
"""
A FlaggingCallback that saves flagged data to a Hugging Face dataset in JSONL format.
A callback that saves flagged data (both the input and output data)
to a Hugging Face dataset in JSONL format.
Each data sample is saved in a different JSONL file,
allowing multiple users to use flagging simultaneously.
Saving to a single CSV would cause errors as only one user can edit at the same time.
Example:
import gradio as gr
hf_writer = gr.HuggingFaceDatasetJSONSaver(HF_API_TOKEN, "image-classification-mistakes")
def image_classifier(inp):
return {'cat': 0.3, 'dog': 0.7}
demo = gr.Interface(fn=image_classifier, inputs="image", outputs="label",
allow_flagging="manual", flagging_callback=hf_writer)
Guides: using_flagging
"""
def __init__(
@ -384,17 +394,12 @@ class HuggingFaceDatasetJSONSaver(FlaggingCallback):
verbose: bool = True,
):
"""
Params:
hf_token (str): The token to use to access the huggingface API.
dataset_name (str): The name of the dataset to save the data to, e.g.
"image-classifier-1"
organization (str): The name of the organization to which to attach
the datasets. If None, the dataset attaches to the user only.
private (bool): If the dataset does not already exist, whether it
should be created as a private dataset or public. Private datasets
may require paid huggingface.co accounts
verbose (bool): Whether to print out the status of the dataset
creation.
Parameters:
hf_token: The token to use to access the huggingface API.
dataset_name: The name of the dataset to save the data to, e.g. "image-classifier-1"
organization: The name of the organization to which to attach the datasets. If None, the dataset attaches to the user only.
private: If the dataset does not already exist, whether it should be created as a private dataset or public. Private datasets may require paid huggingface.co accounts
verbose: Whether to print out the status of the dataset creation.
"""
self.hf_token = hf_token
self.dataset_name = dataset_name