ChiBenevisamPas commited on
Commit
79e74a8
·
verified ·
1 Parent(s): 73eca9d

Update def PDF

Browse files
Files changed (1) hide show
  1. app.py +10 -2
app.py CHANGED
@@ -114,13 +114,17 @@ def write_word(transcription, output_file, tokenizer=None, translation_model=Non
114
 
115
  doc.save(output_file)
116
 
 
 
 
 
117
  def write_pdf(transcription, output_file, tokenizer=None, translation_model=None):
118
  """Creates a PDF document from the transcription without timestamps."""
119
  pdf = FPDF()
120
  pdf.add_page()
121
 
122
  # Set up the font for Farsi (Unicode-compliant)
123
- font_path = "/home/user/app/B-NAZANIN.TTF" # Adjust this path as per your environment
124
  pdf.add_font('B-NAZANIN', '', font_path, uni=True)
125
  pdf.set_font('B-NAZANIN', size=12)
126
 
@@ -130,7 +134,11 @@ def write_pdf(transcription, output_file, tokenizer=None, translation_model=None
130
  if translation_model:
131
  text = translate_text(text, tokenizer, translation_model)
132
 
133
- pdf.multi_cell(0, 10, f"{i + 1}. {text.strip()}", align='R') # Right-align for Farsi
 
 
 
 
134
 
135
  pdf.output(output_file)
136
 
 
114
 
115
  doc.save(output_file)
116
 
117
+ def reverse_text_for_rtl(text):
118
+ # Reverse each word in the text to display it correctly in RTL
119
+ return ' '.join([word[::-1] for word in text.split()])
120
+
121
  def write_pdf(transcription, output_file, tokenizer=None, translation_model=None):
122
  """Creates a PDF document from the transcription without timestamps."""
123
  pdf = FPDF()
124
  pdf.add_page()
125
 
126
  # Set up the font for Farsi (Unicode-compliant)
127
+ font_path = "/home/user/app/B-NAZANIN.ttf" # Ensure the correct path to the font file
128
  pdf.add_font('B-NAZANIN', '', font_path, uni=True)
129
  pdf.set_font('B-NAZANIN', size=12)
130
 
 
134
  if translation_model:
135
  text = translate_text(text, tokenizer, translation_model)
136
 
137
+ # Reverse the text for proper RTL display
138
+ reversed_text = reverse_text_for_rtl(text)
139
+
140
+ # Add the reversed text to the PDF, right-aligned for Farsi
141
+ pdf.multi_cell(0, 10, f"{i + 1}. {reversed_text.strip()}", align='R')
142
 
143
  pdf.output(output_file)
144