Update app.py
Browse files
app.py
CHANGED
|
@@ -10,6 +10,7 @@ from pathlib import Path
|
|
| 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
|
|
@@ -25,22 +26,27 @@ def install_libreoffice():
|
|
| 25 |
try:
|
| 26 |
print("Installing LibreOffice...")
|
| 27 |
# Update package lists
|
| 28 |
-
subprocess.run(['
|
| 29 |
|
| 30 |
# Install LibreOffice
|
| 31 |
-
subprocess.run(['
|
| 32 |
|
| 33 |
print("LibreOffice installed successfully.")
|
| 34 |
except subprocess.CalledProcessError as e:
|
| 35 |
print(f"Failed to install LibreOffice: {e}")
|
| 36 |
-
|
|
|
|
| 37 |
else:
|
| 38 |
print("LibreOffice installation is only supported on Linux systems.")
|
| 39 |
|
| 40 |
# Install LibreOffice if on Linux
|
| 41 |
-
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
| 43 |
|
|
|
|
| 44 |
class WordToPDFConverter:
|
| 45 |
"""
|
| 46 |
A cross-platform Word to PDF converter that preserves formatting and hyperlinks.
|
|
|
|
| 10 |
def install_libreoffice():
|
| 11 |
"""
|
| 12 |
Install LibreOffice on Linux systems if not already installed.
|
| 13 |
+
Optimized for Hugging Face Spaces environment.
|
| 14 |
"""
|
| 15 |
try:
|
| 16 |
# Check if LibreOffice is already installed
|
|
|
|
| 26 |
try:
|
| 27 |
print("Installing LibreOffice...")
|
| 28 |
# Update package lists
|
| 29 |
+
subprocess.run(['apt-get', 'update'], check=True)
|
| 30 |
|
| 31 |
# Install LibreOffice
|
| 32 |
+
subprocess.run(['apt-get', 'install', '-y', 'libreoffice'], check=True)
|
| 33 |
|
| 34 |
print("LibreOffice installed successfully.")
|
| 35 |
except subprocess.CalledProcessError as e:
|
| 36 |
print(f"Failed to install LibreOffice: {e}")
|
| 37 |
+
# Don't exit, as this might prevent the app from starting
|
| 38 |
+
print("Continuing without LibreOffice. Conversion on Linux may fail.")
|
| 39 |
else:
|
| 40 |
print("LibreOffice installation is only supported on Linux systems.")
|
| 41 |
|
| 42 |
# Install LibreOffice if on Linux
|
| 43 |
+
try:
|
| 44 |
+
if system() == "Linux":
|
| 45 |
+
install_libreoffice()
|
| 46 |
+
except Exception as e:
|
| 47 |
+
print(f"Error during LibreOffice installation: {e}")
|
| 48 |
|
| 49 |
+
|
| 50 |
class WordToPDFConverter:
|
| 51 |
"""
|
| 52 |
A cross-platform Word to PDF converter that preserves formatting and hyperlinks.
|