Spaces:
Sleeping
Sleeping
Update def PDF
Browse files93 unmodified lines94959697989910010110210310410510610710810911011111293 unmodified linesdoc.save(output_file)def write_pdf(transcription, output_file, tokenizer=None, translation_model=None):"""Creates a PDF document from the transcription without timestamps."""pdf = FPDF()pdf.set_auto_page_break(auto=True, margin=15)pdf.add_page()pdf.set_font("Arial", size=12)for i, segment in enumerate(transcription['segments']):text = segment['text']if translation_model:text = translate_text(text, tokenizer, translation_model)pdf.multi_cell(0, 10, f"{i + 1}. {text.strip()}")pdf.output(output_file)93 unmodified lines94959697989910010110210310410510610710810911011111211311411511611711893 unmodified linesdoc.save(output_file)def write_pdf(transcription, output_file, tokenizer=None, translation_model=None):"""Creates a PDF document from the transcription."""pdf = FPDF()pdf.set_auto_page_break(auto=True, margin=15)pdf.add_page()pdf.set_font("Arial", size=12)for i, segment in enumerate(transcription['segments']):start = segment['start']end = segment['end']text = segment['text']if translation_model:text = translate_text(text, tokenizer, translation_model)# Ensure the text is encoded to 'latin1' with errors replaced by safe equivalentssafe_text = text.encode('latin1', 'replace').decode('latin1')# Write the safe text to the PDFpdf.multi_cell(0, 10, f"{i + 1}. {safe_text}")pdf.output(output_file)
app.py+8-2