def makeTransliteration_only(**kwargs): import docx from docx.shared import Inches from conversion.translation.script_reading import breaksen, getRefined, getSlugAndNonSlug, getSpeakers, getScenes from conversion.translation.detection import language_detector,script_det from conversion.translation.script_writing import addSlugLine, addActionLine,addTransition, addSpeaker, addParenthetical, addDialogue, dual_script from tqdm import tqdm translation_and_transliteration=kwargs.get('translation_and_transliteration') dial_dest_script=kwargs.get('dial_dest_script') dual_dial_script=kwargs.get('dual_dial_script') original_file=kwargs.get('original_file') dial_dest_lang=kwargs.get('dial_dest_lang') is_dialogue_transliteration_required=kwargs.get("is_dialogue_transliteration_required") is_action_line_transliteration_required=kwargs.get("is_action_line_transliteration_required") action_line_dest_script=kwargs.get("action_line_dest_script") action_line_src_lang=kwargs.get("action_line_src_lang") action_line_src_script=kwargs.get("action_line_src_script") doc2 = docx.Document() sections = doc2.sections for section in sections: section.top_margin = Inches(0.2) section.bottom_margin = Inches(0.2) section.left_margin = Inches(0.2) section.right_margin = Inches(0.2) section = doc2.sections[-1] new_height = section.page_width section.page_width = section.page_height section.page_height = new_height name = 'Final table '+doc_file doc2.add_heading(name, 0) doc_para = doc2.add_paragraph() doc_para.add_run('Translation resources used : Google, IBM watson, AWS, Azure, Lingvanex, Yandex').bold = True table2 = doc2.add_table(rows=1,cols=4) table2.style = 'TableGrid' hdr_Cells = table2.rows[0].cells hdr_Cells[0].paragraphs[0].add_run("Input").bold=True hdr_Cells[1].paragraphs[0].add_run("Output1").bold=True hdr_Cells[2].paragraphs[0].add_run("Output2").bold=True hdr_Cells[3].paragraphs[0].add_run("Output3").bold=True refined,total_scenes = getRefined(filename2) sluglines,without_slug = getSlugAndNonSlug(refined) characters = getSpeakers(without_slug) scenes1,actionline,parenthetical_lis,speakers,dialogues = getScenes(refined,total_scenes,characters) non_dial_src_lang=None dial_src_lang=None dial_src_script=None for scene in tqdm(scenes1): for i,line in enumerate(scene): if i == 0: continue if type(line)==type(""): non_dial_src_lang = language_detector(line) else: [speaker] = line.keys() if speaker == 'Transition': continue if line[speaker][0] != 'NONE': continue dial_src_lang = language_detector(line[speaker][2]) dial_src_script = script_det(line[speaker][2]) if non_dial_src_lang and dial_src_lang: break print("non_dial_src_lang", non_dial_src_lang) print("dial_src_lang", dial_src_lang) print("dial_src_script", dial_src_script) j = 0 for scene in tqdm(scenes1[:]): for i,line in enumerate(scene): if i == 0: addSlugLine(doc,line) continue if type(line)==type(""): trans_text=line if is_action_line_transliteration_required: trans_text=transliterate(action_line_dest_script,action_line_src_script,action_line_src_lang,line) addActionLine(doc, trans_text, non_dial_src_lang) else: print("In dialogue") [speaker] = line.keys() if speaker == 'Transition': # if want to translate transition also along with action line use addTransition(doc,translator.translate(speaker,dest = gtrans_dict[actionline_dest_lang]).text) addTransition(doc,line[speaker]) continue addSpeaker(doc,speaker) if line[speaker][0] != 'NONE': # In parenthitical part non_dial_translate = "no" if non_dial_translate == "yes": out = MNF_translate(line[speaker][0], non_dial_dest_lang) addParenthetical(doc,out) else: addParenthetical(doc,line[speaker][0]) print("dialogue to be transliterated ", line[speaker][2]) if line[speaker][2] == "": continue trans_text=line[speaker][2] if is_dialogue_transliteration_required: trans_text=transliterate(dial_dest_script,dial_src_script,dial_src_lang,trans_text) if dual_dial_script == "Yes": if translation_and_transliteration == "Yes": dual_script(doc, original_dialogues[j], trans_text, dial_src_lang) j=j+1 else: dual_script(doc, line[speaker][2], trans_text, dial_src_lang) else: addDialogue(doc, trans_text, dial_src_lang) doc.save(doc_file) # file_tr = rf"{basePath}/media/scripts/Final_Table" + str(forFinal.split('.')[0])+"_trans_to_"+str(dial_dest_lang)+'_'+"final.docx" # doc2.save(file_tr) print('done file is saved') return doc_file,scenes1 doc_file=get_doc_file(dial_dest_lang,original_file)