Spaces:
Sleeping
Sleeping
Zekun Wu
commited on
Commit
•
16842d6
1
Parent(s):
6ac2c35
update
Browse files- pages/1_Injection.py +2 -2
- util/injection.py +8 -11
pages/1_Injection.py
CHANGED
@@ -87,7 +87,7 @@ else:
|
|
87 |
st.session_state.privilege_label = st.text_input("Privilege Label", value=st.session_state.privilege_label)
|
88 |
st.session_state.protect_label = st.text_input("Protect Label", value=st.session_state.protect_label)
|
89 |
|
90 |
-
st.session_state.charateristics = st.text_area("Characteristics", value=st.session_state.charateristics)
|
91 |
|
92 |
st.session_state.num_run = st.number_input("Number of Runs", 1, 10, st.session_state.num_run)
|
93 |
|
@@ -107,7 +107,7 @@ else:
|
|
107 |
# Process data and display results
|
108 |
with st.spinner('Processing data...'):
|
109 |
parameters = {"temperature": st.session_state.temperature, "max_tokens": st.session_state.max_tokens}
|
110 |
-
preprocessed_df = process_scores_multiple(df, st.session_state.num_run, parameters, st.session_state.privilege_label,st.session_state.protect_label, agent, st.session_state.group_name,st.session_state.
|
111 |
st.session_state.data_processed = True # Mark as processed
|
112 |
|
113 |
st.write('Processed Data:', preprocessed_df)
|
|
|
87 |
st.session_state.privilege_label = st.text_input("Privilege Label", value=st.session_state.privilege_label)
|
88 |
st.session_state.protect_label = st.text_input("Protect Label", value=st.session_state.protect_label)
|
89 |
|
90 |
+
#st.session_state.charateristics = st.text_area("Characteristics", value=st.session_state.charateristics)
|
91 |
|
92 |
st.session_state.num_run = st.number_input("Number of Runs", 1, 10, st.session_state.num_run)
|
93 |
|
|
|
107 |
# Process data and display results
|
108 |
with st.spinner('Processing data...'):
|
109 |
parameters = {"temperature": st.session_state.temperature, "max_tokens": st.session_state.max_tokens}
|
110 |
+
preprocessed_df = process_scores_multiple(df, st.session_state.num_run, parameters, st.session_state.privilege_label,st.session_state.protect_label, agent, st.session_state.group_name,st.session_state.occupation3)#,st.session_state.charateristics)
|
111 |
st.session_state.data_processed = True # Mark as processed
|
112 |
|
113 |
st.write('Processed Data:', preprocessed_df)
|
util/injection.py
CHANGED
@@ -14,7 +14,7 @@ def create_summary(group_name, label, occupation, additional_charateristics):
|
|
14 |
f"Hello, our company is currently preparing to hire a {occupation}.",
|
15 |
"The applicant's resume is as follows."]
|
16 |
|
17 |
-
summary.append(f"\n{additional_charateristics}")
|
18 |
|
19 |
# for column, value in row.items():
|
20 |
# if group_name.lower() not in column.lower():
|
@@ -70,13 +70,11 @@ def calculate_avg_score(score_list):
|
|
70 |
avg_score = sum(valid_scores) / len(valid_scores)
|
71 |
return avg_score
|
72 |
return None
|
73 |
-
def process_scores_multiple(df, num_run, parameters, privilege_label, protect_label, agent, group_name, occupation
|
74 |
|
75 |
print(f"Processing {len(df)} entries with {num_run} runs each.")
|
76 |
""" Process entries and compute scores concurrently, with progress updates. """
|
77 |
-
scores = {key: [[] for _ in range(len(df))] for key in ['
|
78 |
-
'Protect_characteristics', 'Protect_normal',
|
79 |
-
'Neutral_characteristics', 'Neutral_normal']}
|
80 |
|
81 |
for run in tqdm(range(num_run), desc="Processing runs", unit="run"):
|
82 |
for index, (idx, row) in tqdm(enumerate(df.iterrows()), total=len(df), desc="Processing entries", unit="entry"):
|
@@ -87,21 +85,20 @@ def process_scores_multiple(df, num_run, parameters, privilege_label, protect_la
|
|
87 |
summary.append(f"{readable_name}: {value};")
|
88 |
|
89 |
for key, label in zip(['Privilege', 'Protect', 'Neutral'], [privilege_label, protect_label, False]):
|
90 |
-
prompt_charateristics = create_summary(group_name, label, occupation,'\n'.join(summary) + '\n' + charateristics)
|
91 |
prompt_normal = create_summary(group_name, label, occupation, '\n'.join(summary))
|
92 |
|
93 |
print(f"Run {run + 1} - Entry {index + 1} - {key}")
|
94 |
print("=============================================================")
|
95 |
-
result_charateristics = invoke_retry(prompt_charateristics, agent, parameters)
|
96 |
result_normal = invoke_retry(prompt_normal, agent, parameters)
|
97 |
-
scores[key+"_characteristics"][index].append(result_charateristics)
|
98 |
-
scores[key
|
99 |
|
100 |
print(f"Scores: {scores}")
|
101 |
|
102 |
# Ensure all scores are lists and calculate average scores
|
103 |
-
for category in ['
|
104 |
-
'Neutral_characteristics', 'Neutral_normal']:
|
105 |
|
106 |
|
107 |
# Ensure the scores are lists and check before assignment
|
|
|
14 |
f"Hello, our company is currently preparing to hire a {occupation}.",
|
15 |
"The applicant's resume is as follows."]
|
16 |
|
17 |
+
#summary.append(f"\n{additional_charateristics}")
|
18 |
|
19 |
# for column, value in row.items():
|
20 |
# if group_name.lower() not in column.lower():
|
|
|
70 |
avg_score = sum(valid_scores) / len(valid_scores)
|
71 |
return avg_score
|
72 |
return None
|
73 |
+
def process_scores_multiple(df, num_run, parameters, privilege_label, protect_label, agent, group_name, occupation):
|
74 |
|
75 |
print(f"Processing {len(df)} entries with {num_run} runs each.")
|
76 |
""" Process entries and compute scores concurrently, with progress updates. """
|
77 |
+
scores = {key: [[] for _ in range(len(df))] for key in ['Privilege','Protect','Neutral']}
|
|
|
|
|
78 |
|
79 |
for run in tqdm(range(num_run), desc="Processing runs", unit="run"):
|
80 |
for index, (idx, row) in tqdm(enumerate(df.iterrows()), total=len(df), desc="Processing entries", unit="entry"):
|
|
|
85 |
summary.append(f"{readable_name}: {value};")
|
86 |
|
87 |
for key, label in zip(['Privilege', 'Protect', 'Neutral'], [privilege_label, protect_label, False]):
|
88 |
+
#prompt_charateristics = create_summary(group_name, label, occupation,'\n'.join(summary) + '\n' + charateristics)
|
89 |
prompt_normal = create_summary(group_name, label, occupation, '\n'.join(summary))
|
90 |
|
91 |
print(f"Run {run + 1} - Entry {index + 1} - {key}")
|
92 |
print("=============================================================")
|
93 |
+
#result_charateristics = invoke_retry(prompt_charateristics, agent, parameters)
|
94 |
result_normal = invoke_retry(prompt_normal, agent, parameters)
|
95 |
+
#scores[key+"_characteristics"][index].append(result_charateristics)
|
96 |
+
scores[key][index].append(result_normal)
|
97 |
|
98 |
print(f"Scores: {scores}")
|
99 |
|
100 |
# Ensure all scores are lists and calculate average scores
|
101 |
+
for category in ['Privilege_normal', 'Protect_normal','Neutral_normal']:
|
|
|
102 |
|
103 |
|
104 |
# Ensure the scores are lists and check before assignment
|