James Frecheville commited on
Commit
5cf7c58
·
1 Parent(s): 00f2861

Move browser installation to runtime and improve error handling

Browse files
Files changed (2) hide show
  1. Dockerfile +2 -10
  2. app.py +11 -1
Dockerfile CHANGED
@@ -53,13 +53,6 @@ RUN useradd -m -u 1000 user && \
53
  COPY requirements.txt .
54
  RUN pip install --no-cache-dir -r requirements.txt
55
 
56
- # Install Playwright browsers and dependencies as root
57
- RUN mkdir -p /home/user/.cache/ms-playwright && \
58
- chown -R user:user /home/user/.cache/ms-playwright && \
59
- playwright install chromium && \
60
- playwright install-deps && \
61
- chown -R user:user /home/user/.cache/ms-playwright
62
-
63
  # Copy the rest of the application
64
  COPY . .
65
  RUN chown -R user:user /app
@@ -72,7 +65,6 @@ ENV GRADIO_ALLOW_FLAGGING=false
72
  ENV GRADIO_QUEUE_ENABLED=false
73
  ENV DISPLAY=:99
74
  ENV PLAYWRIGHT_BROWSERS_PATH=/home/user/.cache/ms-playwright
75
- ENV PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1
76
 
77
  # Switch to non-root user
78
  USER user
@@ -80,5 +72,5 @@ USER user
80
  # Expose the port
81
  EXPOSE 7860
82
 
83
- # Run the application with Xvfb
84
- CMD Xvfb :99 -screen 0 1280x1024x24 > /dev/null 2>&1 & python app.py
 
53
  COPY requirements.txt .
54
  RUN pip install --no-cache-dir -r requirements.txt
55
 
 
 
 
 
 
 
 
56
  # Copy the rest of the application
57
  COPY . .
58
  RUN chown -R user:user /app
 
65
  ENV GRADIO_QUEUE_ENABLED=false
66
  ENV DISPLAY=:99
67
  ENV PLAYWRIGHT_BROWSERS_PATH=/home/user/.cache/ms-playwright
 
68
 
69
  # Switch to non-root user
70
  USER user
 
72
  # Expose the port
73
  EXPOSE 7860
74
 
75
+ # Run the application with Xvfb and install browsers
76
+ CMD Xvfb :99 -screen 0 1280x1024x24 > /dev/null 2>&1 & playwright install chromium && python app.py
app.py CHANGED
@@ -1,5 +1,6 @@
1
  import os
2
  import sys
 
3
  from pathlib import Path
4
 
5
  # Add the current directory to Python path
@@ -8,9 +9,18 @@ if str(current_dir) not in sys.path:
8
  sys.path.append(str(current_dir))
9
 
10
  # Set environment variables for Playwright
11
- os.environ["PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD"] = "1"
12
  os.environ["PLAYWRIGHT_BROWSERS_PATH"] = "/home/user/.cache/ms-playwright"
13
 
 
 
 
 
 
 
 
 
 
 
14
  from owl.webapp import create_ui
15
  import gradio as gr
16
 
 
1
  import os
2
  import sys
3
+ import subprocess
4
  from pathlib import Path
5
 
6
  # Add the current directory to Python path
 
9
  sys.path.append(str(current_dir))
10
 
11
  # Set environment variables for Playwright
 
12
  os.environ["PLAYWRIGHT_BROWSERS_PATH"] = "/home/user/.cache/ms-playwright"
13
 
14
+ # Ensure browser is installed
15
+ try:
16
+ from playwright.sync_api import sync_playwright
17
+ with sync_playwright() as p:
18
+ p.chromium.launch()
19
+ except Exception as e:
20
+ print(f"Browser installation error: {e}")
21
+ print("Attempting to install browser...")
22
+ subprocess.run(["playwright", "install", "chromium"], check=True)
23
+
24
  from owl.webapp import create_ui
25
  import gradio as gr
26