mobenta commited on
Commit
e83f3b8
·
verified ·
1 Parent(s): 8324e06

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -3
app.py CHANGED
@@ -28,7 +28,6 @@ def setup_conversion_dirs():
28
  def convert_single_file_with_unoconv(input_path, output_dir):
29
  """
30
  Converts a single DOC/DOCX to PDF using the unoconv command-line utility.
31
- This is the most reliable method on a Linux environment like Hugging Face Spaces.
32
  """
33
  filename = Path(input_path).name
34
 
@@ -50,6 +49,10 @@ def convert_single_file_with_unoconv(input_path, output_dir):
50
  except subprocess.TimeoutExpired:
51
  print(f"Conversion of {filename} timed out.")
52
  return False
 
 
 
 
53
  except Exception as e:
54
  print(f"An unexpected error occurred during conversion of {filename}: {e}")
55
  return False
@@ -90,7 +93,6 @@ def convert_docs_to_pdf(doc_files):
90
  with zipfile.ZipFile(zip_filename, 'w', zipfile.ZIP_DEFLATED) as zipf:
91
  # Only zip the successfully created PDF files
92
  for file in TEMP_OUTPUT_DIR.iterdir():
93
- # The PDF file name will be the original name with a .pdf extension
94
  zipf.write(file, arcname=file.name)
95
 
96
  # 3. Return the results
@@ -106,7 +108,7 @@ with gr.Blocks(title="Multi DOC/DOCX to PDF Converter") as demo:
106
  # Multi DOC/DOCX to PDF Converter 📄➡️📜
107
  Upload multiple Microsoft Word files (.doc or .docx) and get them all converted to PDF in a single downloadable ZIP file.
108
 
109
- **Fixes**: This version uses the **`unoconv`** utility with LibreOffice for reliable conversion on Hugging Face's Linux backend, resolving the `docx2pdf` error.
110
  """
111
  )
112
 
 
28
  def convert_single_file_with_unoconv(input_path, output_dir):
29
  """
30
  Converts a single DOC/DOCX to PDF using the unoconv command-line utility.
 
31
  """
32
  filename = Path(input_path).name
33
 
 
49
  except subprocess.TimeoutExpired:
50
  print(f"Conversion of {filename} timed out.")
51
  return False
52
+ except FileNotFoundError:
53
+ # This is the exact error you are seeing: [Errno 2] No such file or directory: 'unoconv'
54
+ print(f"CRITICAL ERROR: 'unoconv' command not found. It is not installed or not in PATH.")
55
+ return False
56
  except Exception as e:
57
  print(f"An unexpected error occurred during conversion of {filename}: {e}")
58
  return False
 
93
  with zipfile.ZipFile(zip_filename, 'w', zipfile.ZIP_DEFLATED) as zipf:
94
  # Only zip the successfully created PDF files
95
  for file in TEMP_OUTPUT_DIR.iterdir():
 
96
  zipf.write(file, arcname=file.name)
97
 
98
  # 3. Return the results
 
108
  # Multi DOC/DOCX to PDF Converter 📄➡️📜
109
  Upload multiple Microsoft Word files (.doc or .docx) and get them all converted to PDF in a single downloadable ZIP file.
110
 
111
+ **Note**: The system needs LibreOffice and `unoconv` installed to function.
112
  """
113
  )
114