Spaces:
Running
Running
Zekun Wu
commited on
Commit
•
13c9123
1
Parent(s):
e470c67
update
Browse files- util/injection.py +6 -12
util/injection.py
CHANGED
@@ -69,8 +69,8 @@ def invoke_retry(prompt, agent, parameters,string_input=False):
|
|
69 |
while attempts < max_attempts:
|
70 |
try:
|
71 |
score_text = agent.invoke(prompt, **parameters)
|
72 |
-
|
73 |
-
|
74 |
if string_input:
|
75 |
return score_text
|
76 |
score = re.search(r'\d+', score_text)
|
@@ -115,8 +115,8 @@ def process_scores_multiple(df, num_run, parameters, privilege_label, protect_la
|
|
115 |
prompt_charateristics = create_summary(group_name, label, occupation, charateristics)
|
116 |
prompt_normal = create_summary(group_name, label, occupation, '\n'.join(summary))
|
117 |
|
118 |
-
|
119 |
-
|
120 |
result_charateristics = invoke_retry(prompt_charateristics, agent, parameters)
|
121 |
result_normal = invoke_retry(prompt_normal, agent, parameters)
|
122 |
scores[key+"_characteristics"][index].append(result_charateristics)
|
@@ -127,17 +127,12 @@ def process_scores_multiple(df, num_run, parameters, privilege_label, protect_la
|
|
127 |
# Ensure all scores are lists and calculate average scores
|
128 |
for category in ['Privilege_characteristics', 'Privilege_normal', 'Protect_characteristics', 'Protect_normal',
|
129 |
'Neutral_characteristics', 'Neutral_normal']:
|
130 |
-
|
131 |
-
print(f"Processing category: {category}")
|
132 |
-
print(f"Scores: {scores[category]}")
|
133 |
|
134 |
# Ensure the scores are lists and check before assignment
|
135 |
series_data = [lst if isinstance(lst, list) else [lst] for lst in scores[category]]
|
136 |
df[f'{category}_Scores'] = series_data
|
137 |
|
138 |
-
# Debug: Check the Series after assignment
|
139 |
-
print(f"Series for {category}_Scores:\n{df[f'{category}_Scores']}")
|
140 |
-
|
141 |
# Calculate the average score with additional debug info
|
142 |
def calculate_avg_score(score_list):
|
143 |
if isinstance(score_list, list) and score_list:
|
@@ -150,7 +145,6 @@ def process_scores_multiple(df, num_run, parameters, privilege_label, protect_la
|
|
150 |
|
151 |
df[f'{category}_Avg_Score'] = df[f'{category}_Scores'].apply(calculate_avg_score)
|
152 |
|
153 |
-
|
154 |
-
print(f"Average scores for {category}:\n{df[f'{category}_Avg_Score']}")
|
155 |
|
156 |
return df
|
|
|
69 |
while attempts < max_attempts:
|
70 |
try:
|
71 |
score_text = agent.invoke(prompt, **parameters)
|
72 |
+
print(f"Score text: {score_text}")
|
73 |
+
print("=============================================================")
|
74 |
if string_input:
|
75 |
return score_text
|
76 |
score = re.search(r'\d+', score_text)
|
|
|
115 |
prompt_charateristics = create_summary(group_name, label, occupation, charateristics)
|
116 |
prompt_normal = create_summary(group_name, label, occupation, '\n'.join(summary))
|
117 |
|
118 |
+
print(f"Run {run + 1} - Entry {index + 1} - {key}")
|
119 |
+
print("=============================================================")
|
120 |
result_charateristics = invoke_retry(prompt_charateristics, agent, parameters)
|
121 |
result_normal = invoke_retry(prompt_normal, agent, parameters)
|
122 |
scores[key+"_characteristics"][index].append(result_charateristics)
|
|
|
127 |
# Ensure all scores are lists and calculate average scores
|
128 |
for category in ['Privilege_characteristics', 'Privilege_normal', 'Protect_characteristics', 'Protect_normal',
|
129 |
'Neutral_characteristics', 'Neutral_normal']:
|
130 |
+
|
|
|
|
|
131 |
|
132 |
# Ensure the scores are lists and check before assignment
|
133 |
series_data = [lst if isinstance(lst, list) else [lst] for lst in scores[category]]
|
134 |
df[f'{category}_Scores'] = series_data
|
135 |
|
|
|
|
|
|
|
136 |
# Calculate the average score with additional debug info
|
137 |
def calculate_avg_score(score_list):
|
138 |
if isinstance(score_list, list) and score_list:
|
|
|
145 |
|
146 |
df[f'{category}_Avg_Score'] = df[f'{category}_Scores'].apply(calculate_avg_score)
|
147 |
|
148 |
+
|
|
|
149 |
|
150 |
return df
|