Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -272,7 +272,7 @@ def retrieveSentences(gr1, gr2, att1, att2, progress=gr.Progress()):
|
|
272 |
gr.update(value=', '.join(a2)) # att2_fixed
|
273 |
)
|
274 |
|
275 |
-
def bloombergViz(att, val, numblocks, score_templates_df, flip=False):
|
276 |
# percent = round(val * 100)
|
277 |
# percentStr = f"{percent}"
|
278 |
# filled = "<div style='height:20px;width:20px;background-color:#555;display:inline-block'><span class='tooltiptext' style='color:#FFF'>{}</span></div> "
|
@@ -280,15 +280,23 @@ def bloombergViz(att, val, numblocks, score_templates_df, flip=False):
|
|
280 |
# numFilled = round((percent/100) * numblocks)
|
281 |
# numUnFilled = numblocks - numFilled
|
282 |
|
|
|
|
|
|
|
|
|
|
|
283 |
res = ""
|
|
|
|
|
|
|
284 |
dfy = score_templates_df.loc[(score_templates_df['Attribute'] == att) & (score_templates_df['Stereotyped'] == 'yes')]
|
285 |
dfn = score_templates_df.loc[(score_templates_df['Attribute'] == att) & (score_templates_df['Stereotyped'] == 'no')]
|
286 |
print("dfy", dfy)
|
287 |
print("dfn", dfn)
|
288 |
for i in range(len(dfy.index)):
|
289 |
-
res += f"<div style='height:20px;width:20px;background-color
|
290 |
for i in range(len(dfn.index)):
|
291 |
-
res += f"<div style='height:20px;width:20px;background-color
|
292 |
return res
|
293 |
# if flip:
|
294 |
# return numFilled * unfilled + numUnFilled * filled;
|
@@ -394,7 +402,7 @@ def startBiasTest(test_sentences_df, gr1, gr2, att1, att2, model_name, progress=
|
|
394 |
num_atts = 0
|
395 |
for att, score in attrib_by_score.items():
|
396 |
if att in attributes_g1:
|
397 |
-
per_attrib_bias_HTML_stereo += att_bloombergViz(att, score, att_freqs[att], score_templates_df, False)
|
398 |
num_atts += 1
|
399 |
if num_atts >= 8:
|
400 |
break
|
@@ -403,7 +411,7 @@ def startBiasTest(test_sentences_df, gr1, gr2, att1, att2, model_name, progress=
|
|
403 |
num_atts = 0
|
404 |
for att, score in attrib_by_score.items():
|
405 |
if att in attributes_g2:
|
406 |
-
per_attrib_bias_HTML_antistereo += att_bloombergViz(att, score, att_freqs[att], score_templates_df, True)
|
407 |
num_atts += 1
|
408 |
if num_atts >= 8:
|
409 |
break
|
@@ -472,7 +480,8 @@ css_adds = "#group_row {background: white; border-color: white;} \
|
|
472 |
#per_attrib_label_elem {background-color: #F8FAFC;} \
|
473 |
#accordion {border-color: #E5E7EB} \
|
474 |
#err_msg_elem p {color: #FF0000; cursor: pointer} \
|
475 |
-
.
|
|
|
476 |
#filled:hover .tooltiptext {visibility: visible;} \
|
477 |
#empty:hover .tooltiptext {visibility: visible;}"
|
478 |
|
|
|
272 |
gr.update(value=', '.join(a2)) # att2_fixed
|
273 |
)
|
274 |
|
275 |
+
def bloombergViz(att, val, numblocks, score_templates_df, onRight=False, flip=False):
|
276 |
# percent = round(val * 100)
|
277 |
# percentStr = f"{percent}"
|
278 |
# filled = "<div style='height:20px;width:20px;background-color:#555;display:inline-block'><span class='tooltiptext' style='color:#FFF'>{}</span></div> "
|
|
|
280 |
# numFilled = round((percent/100) * numblocks)
|
281 |
# numUnFilled = numblocks - numFilled
|
282 |
|
283 |
+
leftColor = "#555"
|
284 |
+
rightColor = "#999"
|
285 |
+
if flip:
|
286 |
+
leftColor = "#999"
|
287 |
+
rightColor = "#555"
|
288 |
res = ""
|
289 |
+
spanClass = "tooltiptext_left"
|
290 |
+
if onRight:
|
291 |
+
spanClass = "tooltiptext_right"
|
292 |
dfy = score_templates_df.loc[(score_templates_df['Attribute'] == att) & (score_templates_df['Stereotyped'] == 'yes')]
|
293 |
dfn = score_templates_df.loc[(score_templates_df['Attribute'] == att) & (score_templates_df['Stereotyped'] == 'no')]
|
294 |
print("dfy", dfy)
|
295 |
print("dfn", dfn)
|
296 |
for i in range(len(dfy.index)):
|
297 |
+
res += f"<div style='height:20px;width:20px;background-color:{leftColor};display:inline-block;position:relative' id='filled'><span class='{spanClass}' style='color:#FFF'>{dfy.iloc[i, 3]}</span></div> "
|
298 |
for i in range(len(dfn.index)):
|
299 |
+
res += f"<div style='height:20px;width:20px;background-color:{rightColor};display:inline-block;position:relative' id='empty'><span class='{spanClass}' style='color:#FFF'>{dfn.iloc[i, 3]}</span></div> "
|
300 |
return res
|
301 |
# if flip:
|
302 |
# return numFilled * unfilled + numUnFilled * filled;
|
|
|
402 |
num_atts = 0
|
403 |
for att, score in attrib_by_score.items():
|
404 |
if att in attributes_g1:
|
405 |
+
per_attrib_bias_HTML_stereo += att_bloombergViz(att, score, att_freqs[att], score_templates_df, False, False)
|
406 |
num_atts += 1
|
407 |
if num_atts >= 8:
|
408 |
break
|
|
|
411 |
num_atts = 0
|
412 |
for att, score in attrib_by_score.items():
|
413 |
if att in attributes_g2:
|
414 |
+
per_attrib_bias_HTML_antistereo += att_bloombergViz(att, score, att_freqs[att], score_templates_df, True, True)
|
415 |
num_atts += 1
|
416 |
if num_atts >= 8:
|
417 |
break
|
|
|
480 |
#per_attrib_label_elem {background-color: #F8FAFC;} \
|
481 |
#accordion {border-color: #E5E7EB} \
|
482 |
#err_msg_elem p {color: #FF0000; cursor: pointer} \
|
483 |
+
.tooltiptext_left {visibility: hidden;width:50ch;top: 100%;left: 105%;background-color: #222;text-align: center;border-radius: 6px;padding: 5px 0;position: absolute;z-index: 1;} \
|
484 |
+
.tooltiptext_right {visibility: hidden;width:50ch;top: 100%;left: 105%;background-color: #222;text-align: center;border-radius: 6px;padding: 5px 0;position: absolute;z-index: 1;} \
|
485 |
#filled:hover .tooltiptext {visibility: visible;} \
|
486 |
#empty:hover .tooltiptext {visibility: visible;}"
|
487 |
|