younes21000 commited on
Commit
97eba94
1 Parent(s): 8b335f1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -14
app.py CHANGED
@@ -121,52 +121,51 @@ def write_pdf(transcription, output_file, tokenizer=None, translation_model=None
121
 
122
  if os.path.exists(font_path):
123
  try:
124
- registerFont(TTFont('B-Nazanin', font_path))
125
- except TTFError as e:
126
  raise RuntimeError(f"Error registering font: {e}.")
127
  else:
128
  raise FileNotFoundError(f"Font file not found at {font_path}. Please ensure it is available.")
129
-
130
-
131
-
132
  # Set font and size
133
  c.setFont('B-Nazanin', 12)
134
-
135
  # Initialize y position from top of page
136
  y_position = A4[1] - 50 # Start 50 points from top
137
  line_height = 20
138
-
139
  # Process each segment
140
  for i, segment in enumerate(transcription['segments']):
141
  text = segment['text']
142
-
143
  # Translate if translation model is provided
144
  if translation_model:
145
  text = translate_text(text, tokenizer, translation_model)
146
-
147
  # Format the line with segment number
148
  line = f"{i + 1}. {text.strip()}"
149
-
150
  # Reshape and reorder the text for correct RTL display
151
  reshaped_text = arabic_reshaper.reshape(line)
152
  bidi_text = get_display(reshaped_text)
153
-
154
  # Add new page if needed
155
  if y_position < 50: # Leave 50 points margin at bottom
156
  c.showPage()
157
  c.setFont('B-Nazanin', 12)
158
  y_position = A4[1] - 50
159
-
160
  # Draw the text right-aligned
161
  c.drawRightString(A4[0] - 50, y_position, bidi_text) # 50 points margin from right
162
-
163
  # Update y position for next line
164
  y_position -= line_height
165
-
166
  # Save the PDF
167
  c.save()
168
  return output_file
169
 
 
170
  # Helper function to write PowerPoint slides
171
  def write_ppt(transcription, output_file, tokenizer=None, translation_model=None):
172
  ppt = Presentation()
 
121
 
122
  if os.path.exists(font_path):
123
  try:
124
+ pdfmetrics.registerFont(TTFont('B-Nazanin', font_path))
125
+ except Exception as e: # Changed to general exception to avoid missing imports
126
  raise RuntimeError(f"Error registering font: {e}.")
127
  else:
128
  raise FileNotFoundError(f"Font file not found at {font_path}. Please ensure it is available.")
129
+
 
 
130
  # Set font and size
131
  c.setFont('B-Nazanin', 12)
132
+
133
  # Initialize y position from top of page
134
  y_position = A4[1] - 50 # Start 50 points from top
135
  line_height = 20
136
+
137
  # Process each segment
138
  for i, segment in enumerate(transcription['segments']):
139
  text = segment['text']
140
+
141
  # Translate if translation model is provided
142
  if translation_model:
143
  text = translate_text(text, tokenizer, translation_model)
144
+
145
  # Format the line with segment number
146
  line = f"{i + 1}. {text.strip()}"
147
+
148
  # Reshape and reorder the text for correct RTL display
149
  reshaped_text = arabic_reshaper.reshape(line)
150
  bidi_text = get_display(reshaped_text)
151
+
152
  # Add new page if needed
153
  if y_position < 50: # Leave 50 points margin at bottom
154
  c.showPage()
155
  c.setFont('B-Nazanin', 12)
156
  y_position = A4[1] - 50
157
+
158
  # Draw the text right-aligned
159
  c.drawRightString(A4[0] - 50, y_position, bidi_text) # 50 points margin from right
160
+
161
  # Update y position for next line
162
  y_position -= line_height
163
+
164
  # Save the PDF
165
  c.save()
166
  return output_file
167
 
168
+
169
  # Helper function to write PowerPoint slides
170
  def write_ppt(transcription, output_file, tokenizer=None, translation_model=None):
171
  ppt = Presentation()