Skip to content

Commit

Permalink
Merge pull request #430 from AI4Bharat/translation_fixes
Browse files Browse the repository at this point in the history
Translation fixes
  • Loading branch information
Shruti1229 authored Jul 27, 2023
2 parents dcae41f + ed25a20 commit e077fb8
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 12 deletions.
6 changes: 3 additions & 3 deletions backend/organization/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ def list_org_tasks(self, request, pk=None, *args, **kwargs):
task["status"] == "SELECTED_SOURCE"
and task["task_type"] != "VOICEOVER_EDIT"
):
buttons["View"] = True
buttons["View"] = False
task["buttons"] = buttons
else:
projects = (
Expand Down Expand Up @@ -514,7 +514,7 @@ def list_org_tasks(self, request, pk=None, *args, **kwargs):
task["status"] == "SELECTED_SOURCE"
and task["task_type"] != "VOICEOVER_EDIT"
):
buttons["View"] = True
buttons["View"] = False
task["buttons"] = buttons
tasks_list.append(task)
else:
Expand Down Expand Up @@ -565,7 +565,7 @@ def list_org_tasks(self, request, pk=None, *args, **kwargs):
task["status"] == "SELECTED_SOURCE"
and task["task_type"] != "VOICEOVER_EDIT"
):
buttons["View"] = True
buttons["View"] = False
if task["status"] == "FAILED":
buttons["Info"] = True
if task["task_type"] == "VOICEOVER_EDIT":
Expand Down
6 changes: 3 additions & 3 deletions backend/project/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,7 @@ def list_project_tasks(self, request, pk=None, *args, **kwargs):
if data["status"] == "SELECTED_SOURCE":
if data["task_type"] != "VOICEOVER_EDIT":
buttons["Edit"] = True
buttons["View"] = True
# buttons["View"] = True
if (
data["task_type"] == "TRANSLATION_EDIT"
and data["is_active"] == True
Expand All @@ -849,7 +849,7 @@ def list_project_tasks(self, request, pk=None, *args, **kwargs):
video = Video.objects.get(pk=data["video"])
if video.multiple_speaker == True:
buttons["Edit-Speaker"] = True
buttons["View"] = True
# buttons["View"] = False
buttons["Edit"] = False
data["buttons"] = buttons
else:
Expand Down Expand Up @@ -889,7 +889,7 @@ def list_project_tasks(self, request, pk=None, *args, **kwargs):
data["status"] == "SELECTED_SOURCE"
and data["task_type"] != "VOICEOVER_EDIT"
):
buttons["View"] = True
buttons["View"] = False
data["buttons"] = buttons
target_languages_list = list(target_languages)
if "-" in target_languages_list:
Expand Down
10 changes: 9 additions & 1 deletion backend/transcript/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ def export_transcript(request):
content = convert_to_paragraph(lines)
return convert_to_docx(content)
elif export_type == "ytt":
return Response(
{"message": "Soemthing went wrong!."},
status=status.HTTP_400_BAD_REQUEST,
)
if (
transcript.payload != None
and "payload" in transcript.payload.keys()
Expand Down Expand Up @@ -1577,7 +1581,7 @@ def save_transcription(request):
num_words += len(cleaned_text.split(" "))
transcript_obj.payload["word_count"] = num_words
transcript_obj.save()
celery_align_json.delay(transcript_obj.id)
# celery_align_json.delay(transcript_obj.id)
return Response(
{
"task_id": task_id,
Expand Down Expand Up @@ -1620,6 +1624,10 @@ def save_transcription(request):
)
@api_view(["GET"])
def get_word_aligned_json(request):
return Response(
{"message": "Soemthing went wrong!"},
status=status.HTTP_400_BAD_REQUEST,
)
video_id = request.query_params.get("video_id")

if video_id is None:
Expand Down
2 changes: 1 addition & 1 deletion backend/translation/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ def get_batch_translations_using_indictrans_nmt_api(
Returns:
list: List of dictionaries containing the translated sentences.
"""

# Convert language code to language text
source_language_name = LANG_CODE_TO_NAME[source_language]
target_language_name = LANG_CODE_TO_NAME[target_language]
Expand Down Expand Up @@ -195,6 +194,7 @@ def get_batch_translations_using_indictrans_nmt_api(
# Collect the translated sentences
return [translation["target"] for translation in translations_output]
except Exception as e:
logging.info("Error in generating translation Output")
return str(e)


Expand Down
8 changes: 7 additions & 1 deletion backend/translation/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,7 @@ def generate_translation_output(request):
status=status.HTTP_400_BAD_REQUEST,
)

logging.info("Generating Translation for task_id %s", str(task_id))
user = request.user

try:
Expand Down Expand Up @@ -924,7 +925,12 @@ def modify_payload(limit, payload, start_offset, end_offset, translation):
translation.video.language,
translation.task.target_language,
)
payload["payload"][i]["target_text"] = translated_text[0]
if type(translated_text) == list:
payload["payload"][i]["target_text"] = translated_text[0]
else:
logging.info(
"Failed to retranslate for task_id %s", str(translation.task.id)
)
if len(payload["payload"]) == limit:
length = len(payload["payload"])
length_2 = -1
Expand Down
26 changes: 23 additions & 3 deletions backend/video/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
from video.tasks import create_videos_async
from organization.models import Organization
from config import *
from collections import Counter


accepted_languages = [
Expand Down Expand Up @@ -1034,9 +1035,29 @@ def upload_csv_org(request):
new_row = ",".join(row)
csv_data.append(new_row)

if len(csv_data) > 50:
if len(csv_data) > 200:
return Response(
{"message": "Number of rows is greater than 50."},
{"message": "Number of rows is greater than 200."},
status=status.HTTP_400_BAD_REQUEST,
)

all_task_types = []

csv_reader_1 = csv.DictReader(csv_data)
for task in csv_reader_1:
all_task_types.append(task["Task Type"].lower())
# Count the occurrences of each unique string
string_counts = Counter(all_task_types)
# Display the results
asr_tts_tasks = (
string_counts["transcription edit"] + string_counts["voiceover edit"]
)
logging.info("Sum of Transcription and VO tasks is %s", str(asr_tts_tasks))
if asr_tts_tasks > 50:
return Response(
{
"message": "Sum of Transcription and VoiceOver in a CSV can't be more than 50."
},
status=status.HTTP_400_BAD_REQUEST,
)
csv_reader = csv.DictReader(csv_data)
Expand Down Expand Up @@ -1200,7 +1221,6 @@ def upload_csv_org(request):
valid_rows.append(valid_row)
else:
valid_rows.append(valid_row)

if len(errors) > 0:
return Response(
{"message": "Invalid CSV", "response": errors},
Expand Down

0 comments on commit e077fb8

Please sign in to comment.