hlydecker commited on
Commit
0e45862
1 Parent(s): de082fd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -1
app.py CHANGED
@@ -1,11 +1,46 @@
1
  import gradio as gr
2
  import os
3
- from docx2pdf import convert
4
  import subprocess
 
5
  from platform import system
6
  import logging
7
  from pathlib import Path
8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  class WordToPDFConverter:
10
  """
11
  A cross-platform Word to PDF converter that preserves formatting and hyperlinks.
 
1
  import gradio as gr
2
  import os
3
+ import sys
4
  import subprocess
5
+ from docx2pdf import convert
6
  from platform import system
7
  import logging
8
  from pathlib import Path
9
 
10
+ def install_libreoffice():
11
+ """
12
+ Install LibreOffice on Linux systems if not already installed.
13
+ """
14
+ try:
15
+ # Check if LibreOffice is already installed
16
+ subprocess.run(['libreoffice', '--version'],
17
+ stdout=subprocess.PIPE,
18
+ stderr=subprocess.PIPE,
19
+ check=True)
20
+ print("LibreOffice is already installed.")
21
+ return
22
+ except (subprocess.CalledProcessError, FileNotFoundError):
23
+ # If not installed, attempt to install
24
+ if system() == "Linux":
25
+ try:
26
+ print("Installing LibreOffice...")
27
+ # Update package lists
28
+ subprocess.run(['sudo', 'apt-get', 'update'], check=True)
29
+
30
+ # Install LibreOffice
31
+ subprocess.run(['sudo', 'apt-get', 'install', '-y', 'libreoffice'], check=True)
32
+
33
+ print("LibreOffice installed successfully.")
34
+ except subprocess.CalledProcessError as e:
35
+ print(f"Failed to install LibreOffice: {e}")
36
+ sys.exit(1)
37
+ else:
38
+ print("LibreOffice installation is only supported on Linux systems.")
39
+
40
+ # Install LibreOffice if on Linux
41
+ if system() == "Linux":
42
+ install_libreoffice()
43
+
44
  class WordToPDFConverter:
45
  """
46
  A cross-platform Word to PDF converter that preserves formatting and hyperlinks.