NimaBoscarino commited on
Commit
9b6f929
β€’
1 Parent(s): cd14e7a

Add flagging capability

Browse files
Files changed (1) hide show
  1. app.py +26 -0
app.py CHANGED
@@ -1,3 +1,4 @@
 
1
  import gradio as gr
2
  from huggingface_hub import ModelCard, HfApi
3
 
@@ -9,6 +10,13 @@ from compliance_checks import (
9
  ComputationalRequirementsCheck,
10
  )
11
 
 
 
 
 
 
 
 
12
  hf_api = HfApi()
13
 
14
  checks = [
@@ -145,6 +153,13 @@ code {
145
  with a.render():
146
  d.render()
147
 
 
 
 
 
 
 
 
148
  search_results_index.click(
149
  fn=load_model_card,
150
  inputs=[search_results_index, search_results_text],
@@ -157,4 +172,15 @@ code {
157
  outputs=[*compliance_accordions, *compliance_descriptions]
158
  )
159
 
 
 
 
 
 
 
 
 
 
 
 
160
  demo.launch()
 
1
+ import os
2
  import gradio as gr
3
  from huggingface_hub import ModelCard, HfApi
4
 
 
10
  ComputationalRequirementsCheck,
11
  )
12
 
13
+ hf_writer = gr.HuggingFaceDatasetSaver(
14
+ os.getenv('HUGGING_FACE_HUB_TOKEN'),
15
+ organization="society-ethics",
16
+ dataset_name="model-card-regulatory-check-flags",
17
+ private=True
18
+ )
19
+
20
  hf_api = HfApi()
21
 
22
  checks = [
 
153
  with a.render():
154
  d.render()
155
 
156
+ flag = gr.Button(value="Disagree with the result? Click here to flag it! 🚩")
157
+ flag_message = gr.Text(
158
+ show_label=False,
159
+ visible=False,
160
+ value="Thank you for flagging this! We'll use your report to improve the tool πŸ€—"
161
+ )
162
+
163
  search_results_index.click(
164
  fn=load_model_card,
165
  inputs=[search_results_index, search_results_text],
 
172
  outputs=[*compliance_accordions, *compliance_descriptions]
173
  )
174
 
175
+ flag.click(
176
+ fn=lambda x: hf_writer.flag(flag_data=[x]) and gr.Text.update(visible=True),
177
+ inputs=[model_card_box],
178
+ outputs=[flag_message]
179
+ )
180
+
181
+ hf_writer.setup(
182
+ components=[model_card_box],
183
+ flagging_dir="flagged"
184
+ )
185
+
186
  demo.launch()