Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -18,6 +18,8 @@ from docx2pdf import convert
|
|
18 |
import pdfplumber
|
19 |
import docx
|
20 |
import numpy as np
|
|
|
|
|
21 |
|
22 |
# Create temporary directories
|
23 |
temp_dir = tempfile.mkdtemp()
|
@@ -37,7 +39,19 @@ def save_uploaded_file(content):
|
|
37 |
f.write(str(content))
|
38 |
return file_path
|
39 |
|
40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
|
42 |
# def save_uploaded_file(uploaded_file):
|
43 |
# file_path = os.path.join("/tmp", uploaded_file.name)
|
@@ -579,8 +593,8 @@ if uploaded_resume and uploaded_job_description:
|
|
579 |
# Convert the generated .docx to a .pdf
|
580 |
# gen_pdf_path = '/tmp/tailored_resume.pdf'
|
581 |
gen_pdf_path = save_uploaded_file(gen_docx_path)
|
582 |
-
|
583 |
-
save_bytes_as_pdf(gen_docx_path, gen_pdf_path)
|
584 |
# save_docx_as_pdf2(gen_docx_path, gen_pdf_path)
|
585 |
|
586 |
# Display uploaded and generated resumes side-by-side
|
|
|
18 |
import pdfplumber
|
19 |
import docx
|
20 |
import numpy as np
|
21 |
+
import pypandoc
|
22 |
+
|
23 |
|
24 |
# Create temporary directories
|
25 |
temp_dir = tempfile.mkdtemp()
|
|
|
39 |
f.write(str(content))
|
40 |
return file_path
|
41 |
|
42 |
+
def save_docx_as_pdf0(input_path, output_path='output.pdf'):
|
43 |
+
if input_path.lower().endswith('.docx'):
|
44 |
+
try:
|
45 |
+
# Convert .docx to .pdf using pypandoc
|
46 |
+
pypandoc.convert_file(input_path, 'pdf', outputfile=output_path)
|
47 |
+
if not os.path.exists(output_path):
|
48 |
+
raise FileNotFoundError("Conversion failed; output PDF not found.")
|
49 |
+
except Exception as e:
|
50 |
+
st.error(f"Failed to convert DOCX to PDF: {str(e)}")
|
51 |
+
elif input_path.lower().endswith('.pdf'):
|
52 |
+
shutil.copy(input_path, output_path)
|
53 |
+
else:
|
54 |
+
raise ValueError("Unsupported file format. Please upload a .docx or .pdf file.")
|
55 |
|
56 |
# def save_uploaded_file(uploaded_file):
|
57 |
# file_path = os.path.join("/tmp", uploaded_file.name)
|
|
|
593 |
# Convert the generated .docx to a .pdf
|
594 |
# gen_pdf_path = '/tmp/tailored_resume.pdf'
|
595 |
gen_pdf_path = save_uploaded_file(gen_docx_path)
|
596 |
+
save_docx_as_pdf0(gen_docx_path, gen_pdf_path)
|
597 |
+
# save_bytes_as_pdf(gen_docx_path, gen_pdf_path)
|
598 |
# save_docx_as_pdf2(gen_docx_path, gen_pdf_path)
|
599 |
|
600 |
# Display uploaded and generated resumes side-by-side
|