younes21000 commited on
Commit
bb80add
·
verified ·
1 Parent(s): 46a7180

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -6
app.py CHANGED
@@ -113,13 +113,21 @@ def reverse_text_for_rtl(text):
113
  def write_pdf(transcription, output_file, tokenizer=None, translation_model=None):
114
  # Create PDF with A4 page size
115
  c = canvas.Canvas(output_file, pagesize=A4)
116
-
117
- # Register the B-Nazanin font
118
- font_path = "/usr/share/fonts/truetype/custom/B-NAZANIN.TTF" # Update this path as needed
 
 
 
 
119
  try:
120
- pdfmetrics.registerFont(TTFont('B-Nazanin', font_path))
121
- except Exception as e:
122
- raise RuntimeError(f"Error registering font: {e}. Please ensure B-NAZANIN.TTF is available at {font_path}")
 
 
 
 
123
 
124
  # Set font and size
125
  c.setFont('B-Nazanin', 12)
 
113
  def write_pdf(transcription, output_file, tokenizer=None, translation_model=None):
114
  # Create PDF with A4 page size
115
  c = canvas.Canvas(output_file, pagesize=A4)
116
+ # Get the directory where app.py is located
117
+ app_dir = os.path.dirname(os.path.abspath(__file__))
118
+
119
+ # Construct the full path to the font file
120
+ font_path = os.path.join(app_dir, 'B-NAZANIN.TTF')
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)