Laramie2 commited on
Commit
6b24b18
·
verified ·
1 Parent(s): ba6912b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -8
app.py CHANGED
@@ -12,13 +12,25 @@ from typing import Iterable
12
  from gradio.themes import Soft
13
  from gradio.themes.utils import colors, fonts, sizes
14
 
15
- # 自动安装 Playwright 浏览器(如果不存在)
16
- try:
17
- import playwright
18
- # 检查是否已经安装了浏览器,没有则下载
19
- subprocess.run(["playwright", "install", "chromium"], check=True)
20
- except Exception as e:
21
- print(f"Playwright setup failed: {e}")
 
 
 
 
 
 
 
 
 
 
 
 
22
 
23
  # ==========================================
24
  # --- 📁 全局目录配置 (修改为 Session 基础目录) ---
@@ -682,4 +694,4 @@ with gr.Blocks(theme=purple_theme, css=custom_css) as demo:
682
 
683
  if __name__ == "__main__":
684
  # 并发放宽至 5
685
- demo.queue(default_concurrency_limit=5).launch(server_name="0.0.0.0", ssr=False)
 
12
  from gradio.themes import Soft
13
  from gradio.themes.utils import colors, fonts, sizes
14
 
15
+
16
+ import threading
17
+ import subprocess
18
+ # ==========================================
19
+ # --- 🌐 异步安装 Playwright 浏览器 ---
20
+ # ==========================================
21
+ def setup_playwright():
22
+ """在后台静默安装 Playwright,防止阻塞 Gradio 启动导致 HF 500 超时"""
23
+ try:
24
+ import playwright
25
+ print("⏳ [System] Downloading Playwright Chromium in background...")
26
+ # 增加 --with-deps 尝试安装系统级依赖 (虽然在非 root 容器可能失效,但有备无患)
27
+ subprocess.run(["playwright", "install", "chromium"], check=True)
28
+ print("✅ [System] Playwright browsers ready.")
29
+ except Exception as e:
30
+ print(f"❌ [System] Playwright setup failed: {e}")
31
+
32
+ # 这一步非常关键:启动一个后台守护线程去下载,主进程直接往下走!
33
+ threading.Thread(target=setup_playwright, daemon=True).start()
34
 
35
  # ==========================================
36
  # --- 📁 全局目录配置 (修改为 Session 基础目录) ---
 
694
 
695
  if __name__ == "__main__":
696
  # 并发放宽至 5
697
+ demo.queue(default_concurrency_limit=5).launch()