Skip to content

Commit

Permalink
Fix labelannotation label not annotation file error
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabian Wolf committed Aug 8, 2024
1 parent 22672b5 commit 83c86c0
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions webapp/labelannotation/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -713,22 +713,24 @@ def labelannotationselector():
]

for label in labels:
try:
llm_output_values = list(df[label["label_name"]])
# Always choose first label TODO might not be what you want
# llm_output_values = [ast.literal_eval(value)[0] for value in llm_output_values if value != ""]
llm_output_values = extract_first_non_empty_string(llm_output_values)
llm_output_values = list(df[label["label_name"]])
# Always choose first label TODO might not be what you want
# llm_output_values = [ast.literal_eval(value)[0] for value in llm_output_values if value != ""]
llm_output_values = extract_first_non_empty_string(llm_output_values)

if label["label_name"] not in list(df_annotation.keys()):
flash(f"Label {label['label_name']} not in the annotation file.", "danger")
return redirect(url_for("labelannotation.main"))

annotation_values = [value for value in list(df_annotation[label["label_name"]]) if isinstance(value, str)]
if len(set(annotation_values)) == 2 and ("True" in annotation_values and "False" in annotation_values or "true" in annotation_values and "false" in annotation_values or "1" in annotation_values and "0" in annotation_values or 1 in annotation_values and 0 in annotation_values or "yes" in annotation_values and "no" in annotation_values):
label["label_type"] = "boolean"
elif set(llm_output_values) == set(annotation_values):
label["label_type"] = "multiclass"
else:
label["label_type"] = "stringmatch"
label["label_classes"] = ",".join(set(annotation_values))

annotation_values = [value for value in list(df_annotation[label["label_name"]]) if type(value) == str]
if len(set(annotation_values)) == 2 and ("True" in annotation_values and "False" in annotation_values or "true" in annotation_values and "false" in annotation_values or "1" in annotation_values and "0" in annotation_values or 1 in annotation_values and 0 in annotation_values or "yes" in annotation_values and "no" in annotation_values):
label["label_type"] = "boolean"
elif set(llm_output_values) == set(annotation_values):
label["label_type"] = "multiclass"
else:
label["label_type"] = "stringmatch"
label["label_classes"] = ",".join(set(annotation_values))
except:
breakpoint()

form.labels.append_entry(label)

Expand Down

0 comments on commit 83c86c0

Please sign in to comment.