pktpaulie commited on
Commit
99f9960
·
verified ·
1 Parent(s): 7298f9c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -1
app.py CHANGED
@@ -15,6 +15,7 @@ import tempfile
15
  from PIL import Image, ImageDraw, ImageFont
16
  import PyPDF2
17
  from docx2pdf import convert
 
18
  import docx
19
  import numpy as np
20
 
@@ -244,6 +245,28 @@ def save_docx_as_pdf(input_path, output_path='output.pdf'):
244
  # else:
245
  # raise ValueError("Unsupported file format. Please upload a .docx or .pdf file.")
246
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
247
  # def save_docx_as_pdf(input_path, output_path='output.pdf'):
248
  # if input_path.lower().endswith('.docx'):
249
  # from docx2pdf import convert
@@ -534,7 +557,8 @@ if uploaded_resume and uploaded_job_description:
534
  # Convert the generated .docx to a .pdf
535
  # gen_pdf_path = '/tmp/tailored_resume.pdf'
536
  gen_pdf_path = save_uploaded_file(gen_docx_path)
537
- save_docx_as_pdf2(gen_docx_path, gen_pdf_path)
 
538
 
539
  # Display uploaded and generated resumes side-by-side
540
  col1, col2 = st.columns(2)
 
15
  from PIL import Image, ImageDraw, ImageFont
16
  import PyPDF2
17
  from docx2pdf import convert
18
+
19
  import docx
20
  import numpy as np
21
 
 
245
  # else:
246
  # raise ValueError("Unsupported file format. Please upload a .docx or .pdf file.")
247
 
248
+
249
+
250
+ def save_docx_as_pdf6(input_path, output_path='output.pdf'):
251
+ if input_path.lower().endswith('.docx'):
252
+ try:
253
+ # Convert .docx to .pdf using docx2pdf
254
+ convert(input_path, output_path)
255
+ if not os.path.exists(output_path):
256
+ raise FileNotFoundError("Conversion failed; output PDF not found.")
257
+ except Exception as e:
258
+ st.error(f"Failed to convert DOCX to PDF: {str(e)}")
259
+ elif input_path.lower().endswith('.pdf'):
260
+ shutil.copy(input_path, output_path)
261
+ else:
262
+ raise ValueError("Unsupported file format. Please upload a .docx or .pdf file.")
263
+
264
+ # Install docx2pdf if not already installed
265
+ try:
266
+ import docx2pdf
267
+ except ImportError:
268
+ !pip install docx2pdf
269
+
270
  # def save_docx_as_pdf(input_path, output_path='output.pdf'):
271
  # if input_path.lower().endswith('.docx'):
272
  # from docx2pdf import convert
 
557
  # Convert the generated .docx to a .pdf
558
  # gen_pdf_path = '/tmp/tailored_resume.pdf'
559
  gen_pdf_path = save_uploaded_file(gen_docx_path)
560
+ save_docx_as_pdf6(gen_docx_path, gen_pdf_path)
561
+ # save_docx_as_pdf2(gen_docx_path, gen_pdf_path)
562
 
563
  # Display uploaded and generated resumes side-by-side
564
  col1, col2 = st.columns(2)