Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -21,11 +21,6 @@ import numpy as np
|
|
21 |
temp_dir = tempfile.mkdtemp()
|
22 |
|
23 |
|
24 |
-
# Checking poppler installation
|
25 |
-
st.write("PDFInfo Path:", os.popen("which pdfinfo").read().strip())
|
26 |
-
st.write("LibreOffice Path:", os.popen("which libreoffice").read().strip())
|
27 |
-
st.write("System PATH:", os.environ['PATH'])
|
28 |
-
|
29 |
import subprocess
|
30 |
|
31 |
def check_poppler():
|
@@ -48,6 +43,8 @@ def save_uploaded_file(content):
|
|
48 |
f.write(str(content))
|
49 |
return file_path
|
50 |
|
|
|
|
|
51 |
# def save_uploaded_file(uploaded_file):
|
52 |
# file_path = os.path.join("/tmp", uploaded_file.name)
|
53 |
# with open(file_path, "wb") as f:
|
@@ -197,15 +194,32 @@ def save_file(file_name):
|
|
197 |
f.write(uploaded_file)
|
198 |
return file_path
|
199 |
|
|
|
200 |
def save_docx_as_pdf(input_path, output_path='output.pdf'):
|
201 |
if input_path.lower().endswith('.docx'):
|
202 |
-
|
203 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
204 |
elif input_path.lower().endswith('.pdf'):
|
205 |
shutil.copy(input_path, output_path)
|
206 |
else:
|
207 |
raise ValueError("Unsupported file format. Please upload a .docx or .pdf file.")
|
208 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
209 |
def save_docx_as_pdf2(doc_content, output_path='output.pdf'):
|
210 |
# Save document content as a .docx file
|
211 |
temp_doc_path = 'temp.docx'
|
@@ -338,7 +352,8 @@ if uploaded_resume and uploaded_job_description:
|
|
338 |
|
339 |
# Convert DOCX to PDF
|
340 |
pdf_path = f"temp_{os.path.basename(temp_doc.name)}.pdf"
|
341 |
-
convert(temp_doc.name, pdf_path)
|
|
|
342 |
|
343 |
# Display resumes side by side
|
344 |
col1, col2 = st.columns(2)
|
|
|
21 |
temp_dir = tempfile.mkdtemp()
|
22 |
|
23 |
|
|
|
|
|
|
|
|
|
|
|
24 |
import subprocess
|
25 |
|
26 |
def check_poppler():
|
|
|
43 |
f.write(str(content))
|
44 |
return file_path
|
45 |
|
46 |
+
|
47 |
+
|
48 |
# def save_uploaded_file(uploaded_file):
|
49 |
# file_path = os.path.join("/tmp", uploaded_file.name)
|
50 |
# with open(file_path, "wb") as f:
|
|
|
194 |
f.write(uploaded_file)
|
195 |
return file_path
|
196 |
|
197 |
+
|
198 |
def save_docx_as_pdf(input_path, output_path='output.pdf'):
|
199 |
if input_path.lower().endswith('.docx'):
|
200 |
+
try:
|
201 |
+
# Attempt to use unoconv
|
202 |
+
subprocess.run(['unoconv', '-o', output_path, input_path])
|
203 |
+
if not os.path.exists(output_path):
|
204 |
+
raise FileNotFoundError("unoconv failed to convert DOCX to PDF")
|
205 |
+
except FileNotFoundError:
|
206 |
+
# Fallback to text-based display
|
207 |
+
with open(output_path, 'w') as f:
|
208 |
+
f.write(input_path.read())
|
209 |
elif input_path.lower().endswith('.pdf'):
|
210 |
shutil.copy(input_path, output_path)
|
211 |
else:
|
212 |
raise ValueError("Unsupported file format. Please upload a .docx or .pdf file.")
|
213 |
|
214 |
+
# def save_docx_as_pdf(input_path, output_path='output.pdf'):
|
215 |
+
# if input_path.lower().endswith('.docx'):
|
216 |
+
# from docx2pdf import convert
|
217 |
+
# convert(input_path, output_path)
|
218 |
+
# elif input_path.lower().endswith('.pdf'):
|
219 |
+
# shutil.copy(input_path, output_path)
|
220 |
+
# else:
|
221 |
+
# raise ValueError("Unsupported file format. Please upload a .docx or .pdf file.")
|
222 |
+
|
223 |
def save_docx_as_pdf2(doc_content, output_path='output.pdf'):
|
224 |
# Save document content as a .docx file
|
225 |
temp_doc_path = 'temp.docx'
|
|
|
352 |
|
353 |
# Convert DOCX to PDF
|
354 |
pdf_path = f"temp_{os.path.basename(temp_doc.name)}.pdf"
|
355 |
+
# convert(temp_doc.name, pdf_path)
|
356 |
+
save_docx_as_pdf(temp_doc.name, pdf_path)
|
357 |
|
358 |
# Display resumes side by side
|
359 |
col1, col2 = st.columns(2)
|