|
from dotenv import load_dotenv |
|
load_dotenv() |
|
import argparse |
|
import os |
|
import subprocess |
|
import sys |
|
import logging |
|
from src.webui.interface import theme_map, create_ui |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _ensure_playwright(): |
|
"""Ensure Playwright and its Chromium browser are installed. |
|
|
|
Hugging Face Spaces (Gradio runtime) does not execute a `postBuild` hook |
|
when the Space type is *Gradio*, therefore we perform the browser |
|
download at runtime. The operations below are idempotent: if the Python |
|
package or the browser binary is already present they complete |
|
immediately. Any failure is logged but will not crash the Web-UI. |
|
""" |
|
|
|
|
|
|
|
|
|
try: |
|
import playwright |
|
except ModuleNotFoundError: |
|
logging.info("Playwright package missing – installing via pip…") |
|
try: |
|
subprocess.check_call([sys.executable, "-m", "pip", "install", "playwright"]) |
|
except subprocess.CalledProcessError as err: |
|
logging.warning("Failed to pip-install Playwright: %s", err) |
|
return |
|
|
|
|
|
|
|
try: |
|
subprocess.run( |
|
["playwright", "install", "--with-deps", "chromium"], |
|
check=True, |
|
stdout=subprocess.PIPE, |
|
stderr=subprocess.STDOUT, |
|
) |
|
except Exception as err: |
|
logging.warning("Playwright install with deps failed: %s", err) |
|
|
|
try: |
|
subprocess.run(["playwright", "install", "chromium"], check=True) |
|
except Exception as err2: |
|
logging.error("Playwright browser installation ultimately failed: %s", err2) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main(): |
|
_ensure_playwright() |
|
|
|
parser = argparse.ArgumentParser(description="Gradio WebUI for Browser Agent") |
|
|
|
|
|
default_port = int(os.getenv("PORT", 7860)) |
|
|
|
parser.add_argument("--ip", type=str, default="0.0.0.0", help="IP address to bind to") |
|
parser.add_argument("--port", type=int, default=default_port, help="Port to listen on") |
|
parser.add_argument("--theme", type=str, default="Ocean", choices=theme_map.keys(), help="Theme to use for the UI") |
|
args = parser.parse_args() |
|
|
|
demo = create_ui(theme_name=args.theme) |
|
demo.queue().launch(server_name=args.ip, server_port=args.port) |
|
|
|
|
|
if __name__ == '__main__': |
|
main() |
|
|