Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom Flagging Callbacks & Flagging for Hugging Face Spaces #362

Merged
merged 27 commits into from Dec 24, 2021

Conversation

abidlabs
Copy link
Member

@abidlabs abidlabs commented Nov 12, 2021

Motivation

We would like the FLAG button on Gradio interfaces to be flexible. In particular, on Hugging Face Spaces, the FLAG button should take the sample and save it to a Hugging Face Dataset. This can be useful for collecting data e.g. for building a crowd-sourced dataset of samples on which a machine learning demo makes mistakes.

Proposal

We create a new FlaggingCallback abstract class whose subclasses must define the following two methods:

  • setup(flagging_dir)
  • flag(self, interface, input_data, output_data, flag_option, flag_index, username)

The setup() method is called once when the Interface is launched and can do things like create a directory, while the flag() method is what is called when the button is actually called and can do things like append to a CSV file.

The Interface object is constructed (through the flagging_callback parameter) with a FlaggingCallback object. The default callback is an object of a class known as CSVLogger which implements the current behavior of the FLAG button. We also define a SimpleCSVLogger for pedagogical reasons.

Most importantly, we define a new HuggingFaceDatasetSaver callback which a user can use to enable the behavior described above (save a flagged sample to a HuggingFace Dataset). In order to do this, a user simply needs to instantiate a HuggingFaceDatasetSaver with hf_foken (their Hugging Face token, which can be provided through Secrets), and dataset_name. The class will take care of the rest utilizing the hub API.

This is work in progress -- feedback welcome.

link T-34

@height
Copy link

height bot commented Nov 12, 2021

This pull request has been linked to 1 task:

💡Tip: Add "Close T-34" to the pull request title or description, to a commit message, or in a comment to mark this task as "Done" when the pull request is merged.

@abidlabs abidlabs requested a review from aliabd November 12, 2021 18:11
@abidlabs
Copy link
Member Author

Link T-34

@abidlabs abidlabs changed the title WIP: Flagging spaces WIP: Flagging spaces Link T-34 Nov 12, 2021
@abidlabs abidlabs changed the title WIP: Flagging spaces Link T-34 WIP: Flagging spaces Nov 15, 2021
@abidlabs abidlabs changed the title WIP: Flagging spaces WIP: Flagging spaces link T-34 Nov 15, 2021
@aliabid94
Copy link
Collaborator

LGTM. Possibly allow them to also pass just a function instead having to implement the whole class (since only the flag option will be necessary in most cases), but your call.

@abidlabs abidlabs changed the title WIP: Flagging spaces link T-34 New Feature: Custom Flagging Handlers & Handlers for Hugging Face Spaces Dec 22, 2021
@gradio-app gradio-app deleted a comment from codecov bot Dec 22, 2021
@gradio-app gradio-app deleted a comment from codecov bot Dec 22, 2021
@abidlabs abidlabs changed the title New Feature: Custom Flagging Handlers & Handlers for Hugging Face Spaces Custom Flagging Callbacks & Flagging for Hugging Face Spaces Dec 22, 2021
@abidlabs abidlabs marked this pull request as draft December 22, 2021 06:30
@abidlabs abidlabs marked this pull request as ready for review December 23, 2021 16:05
@abidlabs
Copy link
Member Author

While this still needs to be polished, merging so that @aliabid94 and other can build off of this.

@abidlabs abidlabs merged commit 18a75e4 into master Dec 24, 2021
@omerXfaruq omerXfaruq deleted the flagging-spaces branch April 21, 2022 22:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants