Spaces:
Running
Running
Create install_poppler.py
Browse files- install_poppler.py +24 -0
install_poppler.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import subprocess
|
| 3 |
+
|
| 4 |
+
def install_poppler():
|
| 5 |
+
"""Install Poppler if not already installed."""
|
| 6 |
+
try:
|
| 7 |
+
# Check if poppler-utils is already installed
|
| 8 |
+
result = subprocess.run(["pdftoppm", "-h"], capture_output=True, text=True)
|
| 9 |
+
if result.returncode == 0:
|
| 10 |
+
print("Poppler is already installed.")
|
| 11 |
+
return
|
| 12 |
+
except FileNotFoundError:
|
| 13 |
+
print("Poppler not found. Proceeding with installation...")
|
| 14 |
+
|
| 15 |
+
# Install Poppler for Linux-based systems (e.g., Hugging Face Spaces)
|
| 16 |
+
try:
|
| 17 |
+
subprocess.run(["sudo", "apt-get", "update"], check=True)
|
| 18 |
+
subprocess.run(["sudo", "apt-get", "install", "-y", "poppler-utils"], check=True)
|
| 19 |
+
print("Poppler installed successfully.")
|
| 20 |
+
except subprocess.CalledProcessError as e:
|
| 21 |
+
print(f"Failed to install Poppler: {e}")
|
| 22 |
+
|
| 23 |
+
# Call the function to ensure Poppler is installed
|
| 24 |
+
install_poppler()
|