shayekh commited on
Commit
0488f64
·
verified ·
1 Parent(s): 8bca9bd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -7
app.py CHANGED
@@ -22,16 +22,20 @@ if not IS_HF:
22
  return args[0]
23
  return decorator
24
  else:
25
- import os
26
  os.environ['SUPERTONIC_CACHE_DIR'] = '/home/user/huggingface'
27
  os.environ["HF_HOME"] = "/home/user/huggingface"
28
  os.environ['XDG_CACHE_HOME'] = "/home/user/huggingface"
29
-
30
- os.environ['PLAYWRIGHT_BROWSERS_PATH'] = "/home/user/huggingface/ms-playwright"
31
 
32
- os.system("python -m playwright install chromium")
33
- os.system("ls -R /home/user/huggingface/ms-playwright/chromium_headless_shell-1223")
34
- os.system("chmod +x /home/user/huggingface/ms-playwright/chromium_headless_shell-1223/chrome-headless-shell-linux64/chrome-headless-shell")
 
 
 
 
 
 
35
 
36
  import gradio as gr
37
  import fitz # PyMuPDF
@@ -86,7 +90,6 @@ def extract_website_content(url, max_images=2):
86
  browser.close()
87
  except Exception as e:
88
  print(f"Playwright headless fetch failed: {e}. Falling back to requests...")
89
- os.system("ls -R /home/user/huggingface/ms-playwright/chromium_headless_shell-1223")
90
  response = requests.get(url, headers=headers, timeout=10)
91
  response.raise_for_status()
92
  html_content = response.content
 
22
  return args[0]
23
  return decorator
24
  else:
25
+ import os, sys, subprocess
26
  os.environ['SUPERTONIC_CACHE_DIR'] = '/home/user/huggingface'
27
  os.environ["HF_HOME"] = "/home/user/huggingface"
28
  os.environ['XDG_CACHE_HOME'] = "/home/user/huggingface"
 
 
29
 
30
+ os.environ['PLAYWRIGHT_BROWSERS_PATH'] = "/home/user/huggingface/ms-playwright"
31
+ # os.system("playwright install chromium")
32
+ result = subprocess.run(
33
+ [sys.executable, "-m", "playwright", "install", "chromium"],
34
+ env={**os.environ},
35
+ check=True,
36
+ stdout=subprocess.PIPE,
37
+ stderr=subprocess.PIPE
38
+ )
39
 
40
  import gradio as gr
41
  import fitz # PyMuPDF
 
90
  browser.close()
91
  except Exception as e:
92
  print(f"Playwright headless fetch failed: {e}. Falling back to requests...")
 
93
  response = requests.get(url, headers=headers, timeout=10)
94
  response.raise_for_status()
95
  html_content = response.content