info
Browse files- Dockerfile +8 -2
- app.py +1 -1
- init_playwright.py +64 -0
Dockerfile
CHANGED
|
@@ -41,6 +41,12 @@ RUN apt-get update && apt-get install -y \
|
|
| 41 |
lsb-release \
|
| 42 |
wget \
|
| 43 |
xdg-utils \
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
&& rm -rf /var/lib/apt/lists/*
|
| 45 |
|
| 46 |
WORKDIR /app
|
|
@@ -60,5 +66,5 @@ COPY . .
|
|
| 60 |
# 暴露端口
|
| 61 |
EXPOSE 7860
|
| 62 |
|
| 63 |
-
# 启动应用
|
| 64 |
-
CMD ["
|
|
|
|
| 41 |
lsb-release \
|
| 42 |
wget \
|
| 43 |
xdg-utils \
|
| 44 |
+
libnss3-dev \
|
| 45 |
+
libxss1 \
|
| 46 |
+
libasound2-dev \
|
| 47 |
+
libxrandr2 \
|
| 48 |
+
libxcomposite1 \
|
| 49 |
+
libxdamage1 \
|
| 50 |
&& rm -rf /var/lib/apt/lists/*
|
| 51 |
|
| 52 |
WORKDIR /app
|
|
|
|
| 66 |
# 暴露端口
|
| 67 |
EXPOSE 7860
|
| 68 |
|
| 69 |
+
# 启动应用 - 先初始化playwright,然后运行应用
|
| 70 |
+
CMD ["sh", "-c", "python init_playwright.py && python app.py"]
|
app.py
CHANGED
|
@@ -9,7 +9,7 @@ import logging
|
|
| 9 |
from main import generate_paper_poster
|
| 10 |
|
| 11 |
|
| 12 |
-
logging.basicConfig(level=logging.
|
| 13 |
logger = logging.getLogger(__name__)
|
| 14 |
|
| 15 |
|
|
|
|
| 9 |
from main import generate_paper_poster
|
| 10 |
|
| 11 |
|
| 12 |
+
logging.basicConfig(level=logging.INFO)
|
| 13 |
logger = logging.getLogger(__name__)
|
| 14 |
|
| 15 |
|
init_playwright.py
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
Playwright初始化脚本
|
| 4 |
+
确保浏览器正确安装和配置
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
import subprocess
|
| 8 |
+
import sys
|
| 9 |
+
import os
|
| 10 |
+
|
| 11 |
+
def check_playwright_installation():
|
| 12 |
+
"""检查playwright是否正确安装"""
|
| 13 |
+
try:
|
| 14 |
+
# 尝试导入playwright
|
| 15 |
+
from playwright.sync_api import sync_playwright
|
| 16 |
+
|
| 17 |
+
# 尝试启动浏览器
|
| 18 |
+
with sync_playwright() as p:
|
| 19 |
+
browser = p.chromium.launch(headless=True)
|
| 20 |
+
browser.close()
|
| 21 |
+
|
| 22 |
+
print("✅ Playwright 浏览器检查通过!")
|
| 23 |
+
return True
|
| 24 |
+
|
| 25 |
+
except Exception as e:
|
| 26 |
+
print(f"❌ Playwright 浏览器检查失败: {e}")
|
| 27 |
+
return False
|
| 28 |
+
|
| 29 |
+
def install_browsers():
|
| 30 |
+
"""安装playwright浏览器"""
|
| 31 |
+
try:
|
| 32 |
+
print("🔄 正在安装 Playwright 浏览器...")
|
| 33 |
+
subprocess.run([sys.executable, "-m", "playwright", "install", "chromium"],
|
| 34 |
+
check=True)
|
| 35 |
+
subprocess.run([sys.executable, "-m", "playwright", "install-deps", "chromium"],
|
| 36 |
+
check=True)
|
| 37 |
+
print("✅ Playwright 浏览器安装完成!")
|
| 38 |
+
return True
|
| 39 |
+
except subprocess.CalledProcessError as e:
|
| 40 |
+
print(f"❌ 浏览器安装失败: {e}")
|
| 41 |
+
return False
|
| 42 |
+
|
| 43 |
+
def main():
|
| 44 |
+
"""主函数"""
|
| 45 |
+
print("🚀 初始化 Playwright...")
|
| 46 |
+
|
| 47 |
+
# 首先检查是否已正确安装
|
| 48 |
+
if check_playwright_installation():
|
| 49 |
+
return True
|
| 50 |
+
|
| 51 |
+
# 如果检查失败,尝试重新安装
|
| 52 |
+
print("🔧 检测到问题,正在重新安装浏览器...")
|
| 53 |
+
if install_browsers():
|
| 54 |
+
# 重新检查
|
| 55 |
+
return check_playwright_installation()
|
| 56 |
+
|
| 57 |
+
return False
|
| 58 |
+
|
| 59 |
+
if __name__ == "__main__":
|
| 60 |
+
success = main()
|
| 61 |
+
if not success:
|
| 62 |
+
print("❌ Playwright 初始化失败!")
|
| 63 |
+
sys.exit(1)
|
| 64 |
+
print("🎉 Playwright 初始化成功!")
|