Spaces:
Sleeping

Corin1998 commited on
Commit
da68aed
·
verified ·
1 Parent(s): 2424d70

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -5
app.py CHANGED
@@ -1,8 +1,27 @@
1
- # app.py(リポジトリ直下)
2
  import gradio as gr
 
3
 
4
- # 既存のUIを組み立てる関数を使う想定
5
- from ui.dash import build_interface
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
- # Spaces はこの変数名 "app" を探します
8
- app: gr.Blocks = build_interface()
 
1
+ # app.py (リポジトリ直下)
2
  import gradio as gr
3
+ import traceback, sys
4
 
5
+ def _build_safe_ui():
6
+ import importlib
7
+ try:
8
+ dash = importlib.import_module("ui.dash")
9
+ if not hasattr(dash, "build_interface"):
10
+ raise RuntimeError("ui.dash.build_interface が見つかりません")
11
+ ui = dash.build_interface()
12
+ if ui is None:
13
+ raise RuntimeError("build_interface() が None を返しました(Blocks を返す必要あり)")
14
+ if not isinstance(ui, gr.Blocks):
15
+ raise RuntimeError(f"build_interface() は gr.Blocks を返してください: {type(ui)}")
16
+ return ui
17
+ except Exception:
18
+ tb = traceback.format_exc()
19
+ print(tb, file=sys.stderr)
20
+ # ここで必ず最低限の Blocks を返す(Spacesがappを見つけられるように)
21
+ fallback = gr.Blocks(title="Init failed")
22
+ with fallback:
23
+ gr.Markdown("### UI init failed\n```\n" + tb + "\n```")
24
+ return fallback
25
 
26
+ # ✅ Spaces はこの名前 "app" を探す。launch() は呼ばないこと。
27
+ app: gr.Blocks = _build_safe_ui()