Rafal commited on
Commit
f818770
1 Parent(s): 80009d7

Added checks on incomplete term entry

Browse files
Files changed (2) hide show
  1. app.py +23 -4
  2. error_messages.py +1 -0
app.py CHANGED
@@ -334,6 +334,25 @@ def retrieveSentences(gr1, gr2, att1, att2, progress=gr.Progress()):
334
  prog_vis = [False]
335
 
336
  #raise gr.Error(NO_TERMS_ENTERED_ERROR)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
337
  else:
338
  tabs = [False, True]
339
  progress(0, desc="Fetching saved sentences...")
@@ -832,11 +851,11 @@ with gr.Blocks(theme=soft, title="Social Bias Testing in Language Models",
832
  ], label="Example Biases", #info="Select a predefied bias specification to fill-out the terms below."
833
  )
834
  with gr.Row(elem_id="group_row"):
835
- group1 = gr.Textbox(label="Words describing Social Group 1", max_lines=1, elem_id="group1_words", elem_classes="input_words", placeholder="brother, father")
836
- group2 = gr.Textbox(label="Words describing Social Group 2", max_lines=1, elem_id="group2_words", elem_classes="input_words", placeholder="sister, mother")
837
  with gr.Row(elem_id="attribute_row"):
838
- att1 = gr.Textbox(label='Stereotype words for Social Group 1', max_lines=1, elem_id="att1_words", elem_classes="input_words", placeholder="science, technology")
839
- att2 = gr.Textbox(label='Stereotype words for Social Group 2', max_lines=1, elem_id="att2_words", elem_classes="input_words", placeholder="poetry, art")
840
  with gr.Row():
841
  gr.Markdown(" ")
842
  get_sent_btn = gr.Button(value="Get Sentences", variant="primary", visible=True)
 
334
  prog_vis = [False]
335
 
336
  #raise gr.Error(NO_TERMS_ENTERED_ERROR)
337
+ elif len(g1) == 0 or len(g2) == 0 or len(a1) == 0 or len(a2) == 0:
338
+ print("Missing terms for some attributes or groups!")
339
+ err_msg = SOME_TERMS_NOT_ENTERED_ERROR
340
+ print(f"Lengths - G1: {len(g1)}, G2: {len(g2)}, A1: {len(a1)}, A2: {len(a2)}")
341
+ if len(g1) == 0:
342
+ err_msg = err_msg.replace("<MISSING>", "words describing both Social Groups")
343
+ elif len(g2) == 0:
344
+ err_msg = err_msg.replace("<MISSING>", "words describing both Social Groups")
345
+ elif len(a1) == 0:
346
+ err_msg = err_msg.replace("<MISSING>", "Stereotype words for both Social Groups")
347
+ elif len(a2) == 0:
348
+ err_msg = err_msg.replace("<MISSING>", "Stereotype words for both Social Groups")
349
+
350
+ err_update = updateErrorMsg(True, err_msg)
351
+ variants = ["primary","secondary","secondary"]
352
+ inter = [True, False, False]
353
+ tabs = [True, False]
354
+ prog_vis = [False]
355
+
356
  else:
357
  tabs = [False, True]
358
  progress(0, desc="Fetching saved sentences...")
 
851
  ], label="Example Biases", #info="Select a predefied bias specification to fill-out the terms below."
852
  )
853
  with gr.Row(elem_id="group_row"):
854
+ group1 = gr.Textbox(label="Words describing Social Group 1", max_lines=1, elem_id="group1_words", elem_classes="input_words", placeholder="he, brother, father, ...")
855
+ group2 = gr.Textbox(label="Words describing Social Group 2", max_lines=1, elem_id="group2_words", elem_classes="input_words", placeholder="she, sister, mother, ...")
856
  with gr.Row(elem_id="attribute_row"):
857
+ att1 = gr.Textbox(label='Stereotype words for Social Group 1', max_lines=1, elem_id="att1_words", elem_classes="input_words", placeholder="science, technology, physics, ...")
858
+ att2 = gr.Textbox(label='Stereotype words for Social Group 2', max_lines=1, elem_id="att2_words", elem_classes="input_words", placeholder="poetry, art, dance, ...")
859
  with gr.Row():
860
  gr.Markdown(" ")
861
  get_sent_btn = gr.Button(value="Get Sentences", variant="primary", visible=True)
error_messages.py CHANGED
@@ -5,5 +5,6 @@ OPENAI_INIT_ERROR = "Incorrect OpenAI key, got error from API: <ERR>."
5
  OPENAI_KEY_WRONG = "The OpenAI key appears incorrect."
6
  OPENAI_KEY_EMPTY = "You need to provide a valid OpenAI key to enable generation. Rest assured, we do not store the key you provide."
7
  NO_TERMS_ENTERED_ERROR = "Please first enter some terms to specify social bias to test."
 
8
  BIAS_SENTENCES_MISMATCH_ERROR = "Terms from bias specification don't correspond to test sentences. Please make sure to find/regenerate test sentences after changing bias specification!"
9
  MODEL_NOT_LOADED_ERROR = "Tested Model [M] did not lead correctly. Please try reploading the space."
 
5
  OPENAI_KEY_WRONG = "The OpenAI key appears incorrect."
6
  OPENAI_KEY_EMPTY = "You need to provide a valid OpenAI key to enable generation. Rest assured, we do not store the key you provide."
7
  NO_TERMS_ENTERED_ERROR = "Please first enter some terms to specify social bias to test."
8
+ SOME_TERMS_NOT_ENTERED_ERROR = "Please first enter some <MISSING>."
9
  BIAS_SENTENCES_MISMATCH_ERROR = "Terms from bias specification don't correspond to test sentences. Please make sure to find/regenerate test sentences after changing bias specification!"
10
  MODEL_NOT_LOADED_ERROR = "Tested Model [M] did not lead correctly. Please try reploading the space."