moizshah956 commited on
Commit
5615b3b
Β·
verified Β·
1 Parent(s): 7bca3aa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -5
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: