diff --git a/CHANGELOG.md b/CHANGELOG.md index 464cdf7144..46d3d00d60 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/gradio/flagging.py b/gradio/flagging.py index b22eb1f216..da3e5dde69 100644 --- a/gradio/flagging.py +++ b/gradio/flagging.py @@ -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