From 5c6b91da3b06d2d98fc981caba387513fe9f5baa Mon Sep 17 00:00:00 2001 From: Tahir <68889901+tahirjmakhdoomi@users.noreply.github.com> Date: Sat, 7 Dec 2024 11:29:25 +0530 Subject: [PATCH] Update views.py --- backend/projects/views.py | 69 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 66 insertions(+), 3 deletions(-) diff --git a/backend/projects/views.py b/backend/projects/views.py index 637837638..c2816c7d7 100644 --- a/backend/projects/views.py +++ b/backend/projects/views.py @@ -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", @@ -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