diff --git a/backend/organization/views.py b/backend/organization/views.py index 0cab44a5..64ccb5d6 100644 --- a/backend/organization/views.py +++ b/backend/organization/views.py @@ -496,6 +496,9 @@ def list_org_tasks(self, request, pk=None, *args, **kwargs): task["updated_at"] ).replace(tzinfo=None): buttons["Reopen"] = False + if "TRANSLATION_VOICEOVER" in task["task_type"]: + if task["status"] in ["SELECTED_SOURCE", "FAILED"] and task["is_active"] is False: + buttons["Regenerate"] = True if task["status"] == "POST_PROCESS": buttons["Update"] = True if task["status"] == "FAILED": diff --git a/backend/project/views.py b/backend/project/views.py index 8eb00844..d6d29d9a 100644 --- a/backend/project/views.py +++ b/backend/project/views.py @@ -861,6 +861,9 @@ def list_project_tasks(self, request, pk=None, *args, **kwargs): data["updated_at"] ).replace(tzinfo=None): buttons["Reopen"] = False + if "TRANSLATION_VOICEOVER" in data["task_type"]: + if data["status"] in ["SELECTED_SOURCE", "FAILED"] and data["is_active"] is False: + buttons["Regenerate"] = True if data["status"] == "POST_PROCESS": buttons["Update"] = True if data["status"] == "FAILED": diff --git a/backend/task/views.py b/backend/task/views.py index f2ca340b..84fefd8e 100644 --- a/backend/task/views.py +++ b/backend/task/views.py @@ -87,7 +87,7 @@ from rest_framework.decorators import parser_classes from rest_framework.parsers import MultiPartParser, FormParser import regex - +from translation.views import regenerate_translation_voiceover def get_export_translation(request, task_id, export_type): new_request = HttpRequest() @@ -3392,6 +3392,12 @@ def regenerate_response(self, request, pk, *args, **kwargs): elif task.task_type == "VOICEOVER_EDIT": celery_tts_call.delay(task_id=task.id) api = "TTS" + elif task.task_type == "TRANSLATION_VOICEOVER_EDIT": + if regenerate_translation_voiceover(task.id) is False: + return Response( + {"message": "Transcription task is not complete yet"}, status=status.HTTP_400_BAD_REQUEST + ) + api = "NMT-TTS" else: return Response( {"message": "Invalid task"}, status=status.HTTP_400_BAD_REQUEST diff --git a/backend/transcript/views.py b/backend/transcript/views.py index a9aa6e1a..94ea0ec9 100644 --- a/backend/transcript/views.py +++ b/backend/transcript/views.py @@ -1362,8 +1362,6 @@ def change_active_status_of_next_tasks(task, transcript_obj): translation.save() if source_type == None or source_type == "MACHINE_GENERATED": source_type = "MACHINE_GENERATED" - translation.transcript = transcript_obj - translation.save() celery_nmt_tts_call.delay(task_id=translation.task.id) else: payloads = generate_translation_payload( diff --git a/backend/translation/views.py b/backend/translation/views.py index 1edd6838..8013e71b 100644 --- a/backend/translation/views.py +++ b/backend/translation/views.py @@ -69,7 +69,8 @@ from transcript.utils.timestamp import * from django.core.mail import EmailMultiAlternatives from django.conf import settings - +from transcript.views import get_transcript_id +from task.tasks import celery_nmt_tts_call @api_view(["GET"]) def get_translation_export_types(request): @@ -2335,3 +2336,17 @@ def get_translation_report(request): res.append(temp_data) return Response(res, status=status.HTTP_200_OK) + +def regenerate_translation_voiceover(task_id): + task_obj = Task.objects.get(pk=task_id) + video = Video.objects.filter(id=task_obj.video_id).first() + transcription_task = Task.objects.filter(video=video, task_type="TRANSCRIPTION_EDIT", status="COMPLETE").first() + if transcription_task is None: + return False + transcript = get_transcript_id(transcription_task) + transcript_obj = Transcript.objects.get(pk=transcript.id) + translation = Translation.objects.filter(task=task_obj).first() + translation.transcript = transcript_obj + translation.save() + celery_nmt_tts_call.delay(task_id) + return True \ No newline at end of file