Zekun Wu
commited on
Commit
Β·
093cdcd
1
Parent(s):
7d9af7f
update
Browse files- pages/1_Demo_1.py +27 -11
pages/1_Demo_1.py
CHANGED
|
@@ -10,6 +10,26 @@ import os
|
|
| 10 |
st.set_page_config(page_title="Gender Bias Analysis", page_icon="π", layout="wide")
|
| 11 |
st.title('Gender Bias Analysis in Text Generation')
|
| 12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
# Password protection function
|
| 14 |
def check_password():
|
| 15 |
def password_entered():
|
|
@@ -18,16 +38,12 @@ def check_password():
|
|
| 18 |
else:
|
| 19 |
st.error("Incorrect Password, please try again.")
|
| 20 |
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
if not st.session_state['password_correct']:
|
| 25 |
-
password_input = st.text_input("Enter Password:", type="password")
|
| 26 |
-
st.button("Submit", on_click=password_entered)
|
| 27 |
|
| 28 |
# Data loading function
|
| 29 |
def load_data():
|
| 30 |
-
if 'bold'
|
| 31 |
st.session_state['bold'] = load_dataset("AlexaAI/bold", split="train")
|
| 32 |
|
| 33 |
# Sampling function
|
|
@@ -95,7 +111,7 @@ def evaluate_regard():
|
|
| 95 |
st.json(regard_results_avg)
|
| 96 |
|
| 97 |
# Main app logic
|
| 98 |
-
if not st.session_state
|
| 99 |
check_password()
|
| 100 |
else:
|
| 101 |
st.sidebar.success("Password Verified. Proceed with the demo.")
|
|
@@ -103,7 +119,7 @@ else:
|
|
| 103 |
|
| 104 |
st.subheader('Step 1: Set Data Size')
|
| 105 |
data_size = st.slider('Select number of samples per category:', min_value=1, max_value=50,
|
| 106 |
-
value=st.session_state
|
| 107 |
st.session_state['data_size'] = data_size
|
| 108 |
|
| 109 |
if st.button('Show Data'):
|
|
@@ -111,12 +127,12 @@ else:
|
|
| 111 |
st.write(f'Sampled {data_size} female and male American actors.')
|
| 112 |
display_samples()
|
| 113 |
|
| 114 |
-
if st.session_state
|
| 115 |
st.subheader('Step 2: Generate Text')
|
| 116 |
if st.button('Generate Text'):
|
| 117 |
generate_text()
|
| 118 |
|
| 119 |
-
if st.session_state
|
| 120 |
st.subheader('Step 3: Evaluate')
|
| 121 |
display_samples()
|
| 122 |
if st.button('Evaluate'):
|
|
|
|
| 10 |
st.set_page_config(page_title="Gender Bias Analysis", page_icon="π", layout="wide")
|
| 11 |
st.title('Gender Bias Analysis in Text Generation')
|
| 12 |
|
| 13 |
+
# Initialize session state variables
|
| 14 |
+
if 'password_correct' not in st.session_state:
|
| 15 |
+
st.session_state['password_correct'] = False
|
| 16 |
+
if 'data_size' not in st.session_state:
|
| 17 |
+
st.session_state['data_size'] = 10
|
| 18 |
+
if 'bold' not in st.session_state:
|
| 19 |
+
st.session_state['bold'] = None
|
| 20 |
+
if 'female_bold' not in st.session_state:
|
| 21 |
+
st.session_state['female_bold'] = []
|
| 22 |
+
if 'male_bold' not in st.session_state:
|
| 23 |
+
st.session_state['male_bold'] = []
|
| 24 |
+
if 'male_prompts' not in st.session_state:
|
| 25 |
+
st.session_state['male_prompts'] = []
|
| 26 |
+
if 'female_prompts' not in st.session_state:
|
| 27 |
+
st.session_state['female_prompts'] = []
|
| 28 |
+
if 'male_continuations' not in st.session_state:
|
| 29 |
+
st.session_state['male_continuations'] = []
|
| 30 |
+
if 'female_continuations' not in st.session_state:
|
| 31 |
+
st.session_state['female_continuations'] = []
|
| 32 |
+
|
| 33 |
# Password protection function
|
| 34 |
def check_password():
|
| 35 |
def password_entered():
|
|
|
|
| 38 |
else:
|
| 39 |
st.error("Incorrect Password, please try again.")
|
| 40 |
|
| 41 |
+
password_input = st.text_input("Enter Password:", type="password")
|
| 42 |
+
st.button("Submit", on_click=password_entered)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
# Data loading function
|
| 45 |
def load_data():
|
| 46 |
+
if st.session_state['bold'] is None:
|
| 47 |
st.session_state['bold'] = load_dataset("AlexaAI/bold", split="train")
|
| 48 |
|
| 49 |
# Sampling function
|
|
|
|
| 111 |
st.json(regard_results_avg)
|
| 112 |
|
| 113 |
# Main app logic
|
| 114 |
+
if not st.session_state['password_correct']:
|
| 115 |
check_password()
|
| 116 |
else:
|
| 117 |
st.sidebar.success("Password Verified. Proceed with the demo.")
|
|
|
|
| 119 |
|
| 120 |
st.subheader('Step 1: Set Data Size')
|
| 121 |
data_size = st.slider('Select number of samples per category:', min_value=1, max_value=50,
|
| 122 |
+
value=st.session_state['data_size'])
|
| 123 |
st.session_state['data_size'] = data_size
|
| 124 |
|
| 125 |
if st.button('Show Data'):
|
|
|
|
| 127 |
st.write(f'Sampled {data_size} female and male American actors.')
|
| 128 |
display_samples()
|
| 129 |
|
| 130 |
+
if st.session_state['female_bold'] and st.session_state['male_bold']:
|
| 131 |
st.subheader('Step 2: Generate Text')
|
| 132 |
if st.button('Generate Text'):
|
| 133 |
generate_text()
|
| 134 |
|
| 135 |
+
if st.session_state['male_continuations'] and st.session_state['female_continuations']:
|
| 136 |
st.subheader('Step 3: Evaluate')
|
| 137 |
display_samples()
|
| 138 |
if st.button('Evaluate'):
|