Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,24 +4,26 @@ import subprocess
|
|
| 4 |
import sys
|
| 5 |
import os
|
| 6 |
from datetime import datetime
|
|
|
|
| 7 |
def install_playwright_browsers():
|
| 8 |
"""Install Playwright Chromium browsers β works on Hugging Face Spaces."""
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
try:
|
| 10 |
print("π¦ Installing Playwright browsers...")
|
| 11 |
-
# Use check_call to raise error if it fails
|
| 12 |
subprocess.check_call(
|
| 13 |
[sys.executable, "-m", "playwright", "install", "chromium"],
|
| 14 |
-
env={**os.environ, "PLAYWRIGHT_BROWSERS_PATH": "/home/user/.cache/ms-playwright"}
|
| 15 |
)
|
|
|
|
|
|
|
| 16 |
print("β
Playwright browsers installed successfully.")
|
| 17 |
except subprocess.CalledProcessError as e:
|
| 18 |
print(f"β Playwright install failed with code {e.returncode}")
|
| 19 |
-
print(f" Stderr: {e.stderr if e.stderr else 'No stderr'}")
|
| 20 |
-
# If it fails, we still let the app start (but it will crash later)
|
| 21 |
except Exception as e:
|
| 22 |
print(f"β Unexpected error during install: {e}")
|
| 23 |
|
| 24 |
-
# Call this immediately, before any other imports that use Playwright
|
| 25 |
install_playwright_browsers()
|
| 26 |
|
| 27 |
try:
|
|
|
|
| 4 |
import sys
|
| 5 |
import os
|
| 6 |
from datetime import datetime
|
| 7 |
+
os.environ.setdefault("PLAYWRIGHT_BROWSERS_PATH", "/home/user/.cache/ms-playwright")
|
| 8 |
def install_playwright_browsers():
|
| 9 |
"""Install Playwright Chromium browsers β works on Hugging Face Spaces."""
|
| 10 |
+
marker = os.path.join(os.environ["PLAYWRIGHT_BROWSERS_PATH"], ".installed")
|
| 11 |
+
if os.path.exists(marker):
|
| 12 |
+
print("β
Playwright browsers already installed, skipping.")
|
| 13 |
+
return
|
| 14 |
try:
|
| 15 |
print("π¦ Installing Playwright browsers...")
|
|
|
|
| 16 |
subprocess.check_call(
|
| 17 |
[sys.executable, "-m", "playwright", "install", "chromium"],
|
|
|
|
| 18 |
)
|
| 19 |
+
os.makedirs(os.environ["PLAYWRIGHT_BROWSERS_PATH"], exist_ok=True)
|
| 20 |
+
open(marker, "w").close()
|
| 21 |
print("β
Playwright browsers installed successfully.")
|
| 22 |
except subprocess.CalledProcessError as e:
|
| 23 |
print(f"β Playwright install failed with code {e.returncode}")
|
|
|
|
|
|
|
| 24 |
except Exception as e:
|
| 25 |
print(f"β Unexpected error during install: {e}")
|
| 26 |
|
|
|
|
| 27 |
install_playwright_browsers()
|
| 28 |
|
| 29 |
try:
|