Skip to content

Commit

Permalink
Update views.py
Browse files Browse the repository at this point in the history
  • Loading branch information
tahirjmakhdoomi authored Dec 7, 2024
1 parent af10b5a commit 5c6b91d
Showing 1 changed file with 66 additions and 3 deletions.
69 changes: 66 additions & 3 deletions backend/projects/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -878,8 +878,71 @@ def convert_prediction_json_to_annotation_result(pk, proj_type):
# converting prediction_json to result (wherever it exists) for every task.
if prediction_json == None:
return result
for pred_type, pred_json in prediction_json.items():
for idx, val in enumerate(pred_json):
# for pred_type, pred_json in prediction_json.items():
if 'acoustic_normalised_transcribed_json' in pred_json.keys():
for idx, val, val_acoustic in enumerate(zip(pred_json['verbatim_transcribed_json'],pred_json['acoustic_normalised_transcribed_json'])):
label_dict = {
"origin": "manual",
"to_name": "audio_url",
"from_name": "labels",
"original_length": audio_duration,
}
text_dict = {
"origin": "manual",
"to_name": "audio_url",
"from_name": "transcribed_json",
"original_length": audio_duration,
}
text_dict_acoustic = {
"origin": "manual",
"to_name": "audio_url",
"from_name": "transcribed_json",
"original_length": audio_duration,
}
if proj_type == "AcousticNormalisedTranscriptionEditing":
text_dict["from_name"] = 'verbatim_transcribed_json'
text_dict_acoustic["from_name"] = 'acoustic_normalised_transcribed_json'

id = f"shoonya_{idx}s{generate_random_string(13 - len(str(idx)))}"
label_dict["id"] = id
text_dict["id"] = id
text_dict_acoustic["id"] = id

label_dict["type"] = "labels"
text_dict["type"] = "textarea"
text_dict_acoustic["type"] = "textarea"

value_labels = {
"start": val["start"],
"end": val["end"],
"labels": [
next(
speaker
for speaker in speakers_json
if speaker["speaker_id"] == val["speaker_id"]
)["name"]
],
}
value_text = {
"start": val["start"],
"end": val["end"],
"text": [val["text"]],
}
value_text_acoustic = {
"start": val_acoustic["start"],
"end": val_acoustic["end"],
"text": [val_acoustic["text"]],
}

label_dict["value"] = value_labels
text_dict["value"] = value_text
text_dict_acoustic["value"] = value_text_acoustic
# mainly label_dict and text_dict are sent as result
result.append(label_dict)
result.append(text_dict)
result.append(text_dict_acoustic)
else:
for idx, val in enumerate(pred_json['verbatim_transcribed_json']):
label_dict = {
"origin": "manual",
"to_name": "audio_url",
Expand All @@ -893,7 +956,7 @@ def convert_prediction_json_to_annotation_result(pk, proj_type):
"original_length": audio_duration,
}
if proj_type == "AcousticNormalisedTranscriptionEditing":
text_dict["from_name"] = pred_type
text_dict["from_name"] = 'verbatim_transcribed_json'
id = f"shoonya_{idx}s{generate_random_string(13 - len(str(idx)))}"
label_dict["id"] = id
text_dict["id"] = id
Expand Down

0 comments on commit 5c6b91d

Please sign in to comment.