Sonu Prasad commited on
Commit
2861cb3
·
1 Parent(s): 84f0d92

Use Chromium instead of Chrome for compatibility

Browse files
Files changed (3) hide show
  1. Dockerfile +18 -32
  2. bot.py +25 -13
  3. requirements.txt +0 -2
Dockerfile CHANGED
@@ -4,40 +4,34 @@ FROM python:3.11-slim
4
  # Set environment variables
5
  ENV PYTHONDONTWRITEBYTECODE=1
6
  ENV PYTHONUNBUFFERED=1
7
- ENV DISPLAY=:99
 
8
 
9
- # Install system dependencies for Chrome
10
  RUN apt-get update && apt-get install -y --no-install-recommends \
 
 
11
  wget \
12
  gnupg \
13
- unzip \
14
- xvfb \
15
- libgconf-2-4 \
16
- libxss1 \
17
- libnss3 \
18
- libnspr4 \
19
  libasound2 \
20
- libatk1.0-0 \
21
  libatk-bridge2.0-0 \
 
22
  libcups2 \
 
23
  libdrm2 \
24
- libxkbcommon0 \
 
 
 
25
  libxcomposite1 \
26
  libxdamage1 \
 
 
27
  libxrandr2 \
28
- libgbm1 \
29
- libpango-1.0-0 \
30
- libcairo2 \
31
- fonts-liberation \
32
- ca-certificates \
33
- curl \
34
- && rm -rf /var/lib/apt/lists/*
35
-
36
- # Install Chrome
37
- RUN wget -q -O /tmp/chrome.deb https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb \
38
- && apt-get update \
39
- && apt-get install -y --no-install-recommends /tmp/chrome.deb \
40
- && rm /tmp/chrome.deb \
41
  && rm -rf /var/lib/apt/lists/*
42
 
43
  # Create app directory
@@ -51,15 +45,7 @@ RUN pip install --no-cache-dir -r requirements.txt
51
  COPY . .
52
 
53
  # Create directories for uploads with proper permissions
54
- RUN mkdir -p documents uploads && chmod -R 777 documents uploads
55
-
56
- # Create a non-root user for HuggingFace
57
- RUN useradd -m -u 1000 user
58
- USER user
59
- ENV HOME=/home/user
60
- ENV PATH=/home/user/.local/bin:$PATH
61
-
62
- WORKDIR /app
63
 
64
  # Expose port for HuggingFace Spaces
65
  EXPOSE 7860
 
4
  # Set environment variables
5
  ENV PYTHONDONTWRITEBYTECODE=1
6
  ENV PYTHONUNBUFFERED=1
7
+ ENV CHROME_BIN=/usr/bin/chromium
8
+ ENV CHROMEDRIVER_PATH=/usr/bin/chromedriver
9
 
10
+ # Install Chromium and dependencies
11
  RUN apt-get update && apt-get install -y --no-install-recommends \
12
+ chromium \
13
+ chromium-driver \
14
  wget \
15
  gnupg \
16
+ ca-certificates \
17
+ fonts-liberation \
 
 
 
 
18
  libasound2 \
 
19
  libatk-bridge2.0-0 \
20
+ libatk1.0-0 \
21
  libcups2 \
22
+ libdbus-1-3 \
23
  libdrm2 \
24
+ libgbm1 \
25
+ libgtk-3-0 \
26
+ libnspr4 \
27
+ libnss3 \
28
  libxcomposite1 \
29
  libxdamage1 \
30
+ libxfixes3 \
31
+ libxkbcommon0 \
32
  libxrandr2 \
33
+ xdg-utils \
34
+ && apt-get clean \
 
 
 
 
 
 
 
 
 
 
 
35
  && rm -rf /var/lib/apt/lists/*
36
 
37
  # Create app directory
 
45
  COPY . .
46
 
47
  # Create directories for uploads with proper permissions
48
+ RUN mkdir -p documents uploads && chmod 777 documents uploads
 
 
 
 
 
 
 
 
49
 
50
  # Expose port for HuggingFace Spaces
51
  EXPOSE 7860
bot.py CHANGED
@@ -1,7 +1,8 @@
1
  """
2
- Practice Fusion Bot - Headless Chrome Automation
3
  """
4
 
 
5
  import time
6
  import logging
7
  from pathlib import Path
@@ -11,7 +12,6 @@ from selenium import webdriver
11
  from selenium.webdriver.chrome.service import Service
12
  from selenium.webdriver.chrome.options import Options
13
  from selenium.webdriver.common.by import By
14
- from webdriver_manager.chrome import ChromeDriverManager
15
 
16
  import config
17
  from utils import (
@@ -23,7 +23,7 @@ logger = logging.getLogger(__name__)
23
 
24
 
25
  class PracticeFusionBot:
26
- """Headless Chrome bot for Practice Fusion document uploads."""
27
 
28
  def __init__(self, headless: bool = True):
29
  self.headless = headless
@@ -34,23 +34,35 @@ class PracticeFusionBot:
34
  self._setup_driver()
35
 
36
  def _setup_driver(self):
37
- """Initialize Chrome WebDriver with headless options."""
38
  chrome_options = Options()
39
 
40
- for opt in config.CHROME_OPTIONS:
41
- chrome_options.add_argument(opt)
 
 
 
 
 
 
 
42
 
43
- # Additional options for stability
44
- chrome_options.add_argument("--disable-web-security")
45
- chrome_options.add_argument("--allow-running-insecure-content")
46
- chrome_options.add_experimental_option("excludeSwitches", ["enable-automation"])
47
- chrome_options.add_experimental_option("useAutomationExtension", False)
48
 
49
  try:
50
- service = Service(ChromeDriverManager().install())
 
 
 
 
 
 
51
  self.driver = webdriver.Chrome(service=service, options=chrome_options)
52
  self.driver.set_page_load_timeout(config.PAGE_LOAD_TIMEOUT)
53
- self.logger.info("Chrome driver initialized successfully")
54
  except Exception as e:
55
  self.logger.error(f"Failed to initialize driver: {e}")
56
  raise
 
1
  """
2
+ Practice Fusion Bot - Headless Chromium Automation
3
  """
4
 
5
+ import os
6
  import time
7
  import logging
8
  from pathlib import Path
 
12
  from selenium.webdriver.chrome.service import Service
13
  from selenium.webdriver.chrome.options import Options
14
  from selenium.webdriver.common.by import By
 
15
 
16
  import config
17
  from utils import (
 
23
 
24
 
25
  class PracticeFusionBot:
26
+ """Headless Chromium bot for Practice Fusion document uploads."""
27
 
28
  def __init__(self, headless: bool = True):
29
  self.headless = headless
 
34
  self._setup_driver()
35
 
36
  def _setup_driver(self):
37
+ """Initialize Chromium WebDriver with headless options."""
38
  chrome_options = Options()
39
 
40
+ # Headless options
41
+ chrome_options.add_argument("--headless=new")
42
+ chrome_options.add_argument("--no-sandbox")
43
+ chrome_options.add_argument("--disable-dev-shm-usage")
44
+ chrome_options.add_argument("--disable-gpu")
45
+ chrome_options.add_argument("--window-size=1920,1080")
46
+ chrome_options.add_argument("--disable-extensions")
47
+ chrome_options.add_argument("--disable-blink-features=AutomationControlled")
48
+ chrome_options.add_argument("--remote-debugging-port=9222")
49
 
50
+ # Set binary location for Chromium
51
+ chrome_bin = os.environ.get("CHROME_BIN", "/usr/bin/chromium")
52
+ if os.path.exists(chrome_bin):
53
+ chrome_options.binary_location = chrome_bin
 
54
 
55
  try:
56
+ # Use system chromedriver
57
+ chromedriver_path = os.environ.get("CHROMEDRIVER_PATH", "/usr/bin/chromedriver")
58
+ if os.path.exists(chromedriver_path):
59
+ service = Service(chromedriver_path)
60
+ else:
61
+ service = Service()
62
+
63
  self.driver = webdriver.Chrome(service=service, options=chrome_options)
64
  self.driver.set_page_load_timeout(config.PAGE_LOAD_TIMEOUT)
65
+ self.logger.info("Chromium driver initialized successfully")
66
  except Exception as e:
67
  self.logger.error(f"Failed to initialize driver: {e}")
68
  raise
requirements.txt CHANGED
@@ -1,6 +1,4 @@
1
  flask==3.0.0
2
  flask-cors==4.0.0
3
  selenium==4.16.0
4
- webdriver-manager==4.0.1
5
  python-dotenv==1.0.0
6
- gunicorn==21.2.0
 
1
  flask==3.0.0
2
  flask-cors==4.0.0
3
  selenium==4.16.0
 
4
  python-dotenv==1.0.0