Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -22,20 +22,21 @@ try:
|
|
| 22 |
except ImportError:
|
| 23 |
pass
|
| 24 |
|
| 25 |
-
# Install Playwright browsers
|
| 26 |
_playwright_flag = os.path.join(tempfile.gettempdir(), 'playwright_installed')
|
| 27 |
-
|
|
|
|
| 28 |
try:
|
| 29 |
-
# On Linux, --with-deps ensures runtime libraries are pulled where supported
|
| 30 |
cmd = [sys.executable, "-m", "playwright", "install", "chromium"]
|
| 31 |
-
if sys.platform.startswith('linux'):
|
| 32 |
-
cmd += ["--with-deps"]
|
| 33 |
subprocess.run(cmd, check=True)
|
| 34 |
with open(_playwright_flag, 'w') as f:
|
| 35 |
f.write('installed')
|
| 36 |
print("✅ Playwright browsers installed!")
|
| 37 |
except Exception as e:
|
| 38 |
print(f"⚠️ Failed to install Playwright browsers: {e}")
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
# Try to import PyPDF for PDF page extraction
|
| 41 |
PYPDF_AVAILABLE = False
|
|
|
|
| 22 |
except ImportError:
|
| 23 |
pass
|
| 24 |
|
| 25 |
+
# Install Playwright browsers at runtime (disabled by default for hosted envs)
|
| 26 |
_playwright_flag = os.path.join(tempfile.gettempdir(), 'playwright_installed')
|
| 27 |
+
_allow_runtime_install = os.environ.get('PLAYWRIGHT_RUNTIME_INSTALL') == '1'
|
| 28 |
+
if PLAYWRIGHT_AVAILABLE and _allow_runtime_install and not os.path.exists(_playwright_flag):
|
| 29 |
try:
|
|
|
|
| 30 |
cmd = [sys.executable, "-m", "playwright", "install", "chromium"]
|
|
|
|
|
|
|
| 31 |
subprocess.run(cmd, check=True)
|
| 32 |
with open(_playwright_flag, 'w') as f:
|
| 33 |
f.write('installed')
|
| 34 |
print("✅ Playwright browsers installed!")
|
| 35 |
except Exception as e:
|
| 36 |
print(f"⚠️ Failed to install Playwright browsers: {e}")
|
| 37 |
+
else:
|
| 38 |
+
if not _allow_runtime_install:
|
| 39 |
+
print("ℹ️ Skipping runtime Playwright install (build-time install expected).")
|
| 40 |
|
| 41 |
# Try to import PyPDF for PDF page extraction
|
| 42 |
PYPDF_AVAILABLE = False
|