pktpaulie commited on
Commit
77d7db0
·
verified ·
1 Parent(s): bd80b9c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -19
app.py CHANGED
@@ -8,7 +8,7 @@ from similarity_score_refined import similarity_main
8
  from pdf2image import convert_from_path, convert_from_bytes
9
  from docx import Document
10
  import subprocess
11
- import shutil
12
 
13
  import tempfile
14
  from PIL import Image
@@ -23,23 +23,6 @@ temp_dir = tempfile.mkdtemp()
23
 
24
  import subprocess
25
 
26
- def check_poppler_installation():
27
- """Check if poppler is installed and accessible"""
28
- try:
29
- # Try to execute pdftoppm (part of poppler-utils)
30
- result = subprocess.run(['pdftoppm', '-v'],
31
- capture_output=True,
32
- text=True)
33
- st.success("Poppler is installed and accessible")
34
- return True
35
- except FileNotFoundError:
36
- st.warning("Poppler not found in PATH. Using fallback display methods.")
37
- return False
38
-
39
- # Call this at startup
40
- check_poppler_installation()
41
-
42
-
43
  # Helper function to save uploaded files temporarily and return their paths
44
  def save_uploaded_file(content):
45
  if hasattr(content, 'name'): # Check if it's a file-like object
@@ -203,6 +186,28 @@ def save_file(file_name):
203
  f.write(uploaded_file)
204
  return file_path
205
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
206
 
207
  def save_docx_as_pdf(input_path, output_path='output.pdf'):
208
  if input_path.lower().endswith('.docx'):
@@ -426,7 +431,7 @@ if uploaded_resume and uploaded_job_description:
426
 
427
  # Now pass the path to any function that expects a file path
428
  pdf_path = '/tmp/generated_resume.pdf'
429
- save_docx_as_pdf(temp_doc_path, pdf_path)
430
 
431
  # Display the generated PDF or handle further processing
432
  display_doc_as_image(pdf_output_path)
 
8
  from pdf2image import convert_from_path, convert_from_bytes
9
  from docx import Document
10
  import subprocess
11
+ import shutilhttps://huggingface.co/spaces/pktpaulie/resumeMagic
12
 
13
  import tempfile
14
  from PIL import Image
 
23
 
24
  import subprocess
25
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
  # Helper function to save uploaded files temporarily and return their paths
27
  def save_uploaded_file(content):
28
  if hasattr(content, 'name'): # Check if it's a file-like object
 
186
  f.write(uploaded_file)
187
  return file_path
188
 
189
+ import tempfile
190
+
191
+
192
+ def save_bytes_as_pdf(docx_bytes, output_path='output.pdf'):
193
+ # Create a temporary directory
194
+ with tempfile.TemporaryDirectory() as tmp_dir:
195
+ # Write the DOCX bytes to a temporary file
196
+ temp_file = os.path.join(tmp_dir, 'temp.docx')
197
+ with open(temp_file, 'wb') as f:
198
+ f.write(docx_bytes)
199
+
200
+ # Convert the temporary DOCX to PDF
201
+ pdf_path = os.path.join(tmp_dir, 'output.pdf')
202
+ convert(temp_file, pdf_path)
203
+
204
+ # Copy the PDF to the desired output location
205
+ with open(output_path, 'wb') as f:
206
+ with open(pdf_path, 'rb') as src_f:
207
+ f.write(src_f.read())
208
+
209
+ # Clean up the temporary directory
210
+ os.remove(output_path)
211
 
212
  def save_docx_as_pdf(input_path, output_path='output.pdf'):
213
  if input_path.lower().endswith('.docx'):
 
431
 
432
  # Now pass the path to any function that expects a file path
433
  pdf_path = '/tmp/generated_resume.pdf'
434
+ save_bytes_as_pdf(temp_doc_path, pdf_path)
435
 
436
  # Display the generated PDF or handle further processing
437
  display_doc_as_image(pdf_output_path)