techfreakworm commited on
Commit
5c21a0d
·
unverified ·
1 Parent(s): 3010ce9

feat(app): Gradio shell with sidebar nav and empty mode tabs

Browse files
Files changed (1) hide show
  1. app.py +121 -0
app.py ADDED
@@ -0,0 +1,121 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # app.py
2
+ """LTX 2.3 All-in-One — Gradio entry point."""
3
+ from __future__ import annotations
4
+
5
+ import os
6
+ import pathlib
7
+ import sys
8
+
9
+ import gradio as gr
10
+
11
+ import modes
12
+ import ui
13
+
14
+
15
+ # ---------------------------------------------------------------------------
16
+ # Bootstrap — runs once on cold start.
17
+ # ---------------------------------------------------------------------------
18
+
19
+ def _on_spaces() -> bool:
20
+ return bool(os.environ.get("SPACES_ZERO_GPU"))
21
+
22
+
23
+ COMFYUI_REPO = "https://github.com/comfyanonymous/ComfyUI.git"
24
+ # Pinned to the same commit the local git submodule uses (set in Task 5).
25
+ # Override via env var only when intentionally testing a different ComfyUI version.
26
+ COMFYUI_COMMIT = os.environ.get(
27
+ "LTX23_AIO_COMFYUI_COMMIT",
28
+ "eb0686bbb60c83e44c3a3e4f7defd0f589cfef10",
29
+ )
30
+
31
+ CUSTOM_NODES_PINNED: list[tuple[str, str]] = [
32
+ ("https://github.com/Lightricks/ComfyUI-LTXVideo.git", "main"),
33
+ ("https://github.com/kijai/ComfyUI-KJNodes.git", "main"),
34
+ ("https://github.com/rgthree/rgthree-comfy.git", "main"),
35
+ ("https://github.com/Kosinkadink/ComfyUI-VideoHelperSuite.git", "main"),
36
+ ("https://github.com/pythongosssss/ComfyUI-Custom-Scripts.git", "main"),
37
+ ]
38
+
39
+
40
+ def _git_clone(url: str, dst: pathlib.Path, ref: str) -> None:
41
+ import subprocess
42
+ subprocess.check_call(["git", "clone", "--depth", "1", "--branch", ref, url, str(dst)])
43
+
44
+
45
+ def _bootstrap() -> None:
46
+ on_spaces = _on_spaces()
47
+ comfy_dir = pathlib.Path("/data/comfyui" if on_spaces else "comfyui")
48
+
49
+ if on_spaces and not comfy_dir.exists():
50
+ comfy_dir.parent.mkdir(parents=True, exist_ok=True)
51
+ _git_clone(COMFYUI_REPO, comfy_dir, ref=COMFYUI_COMMIT)
52
+ for node_url, node_ref in CUSTOM_NODES_PINNED:
53
+ name = node_url.rstrip(".git").rsplit("/", 1)[-1]
54
+ _git_clone(node_url, comfy_dir / "custom_nodes" / name, ref=node_ref)
55
+ # Install custom node deps
56
+ import subprocess
57
+ for cn in (comfy_dir / "custom_nodes").iterdir():
58
+ req = cn / "requirements.txt"
59
+ if req.exists():
60
+ subprocess.check_call([sys.executable, "-m", "pip", "install", "-r", str(req)])
61
+
62
+ if str(comfy_dir) not in sys.path:
63
+ sys.path.insert(0, str(comfy_dir))
64
+ os.environ.setdefault(
65
+ "COMFY_MODELS_DIR",
66
+ str(pathlib.Path("/data/models") if on_spaces else (comfy_dir / "models")),
67
+ )
68
+
69
+
70
+ _bootstrap()
71
+
72
+
73
+ # ---------------------------------------------------------------------------
74
+ # Gradio app
75
+ # ---------------------------------------------------------------------------
76
+
77
+ _CUSTOM_CSS = """
78
+ .status-card { padding: 14px 16px; border-radius: 10px; background: rgba(255,255,255,0.04); border: 1px solid rgba(255,255,255,0.08); }
79
+ .status-row { display: flex; gap: 14px; align-items: center; margin-bottom: 8px; }
80
+ .status-stage { font-weight: 600; }
81
+ .status-meta { font-size: 12px; opacity: 0.75; }
82
+ .status-bar { height: 6px; background: rgba(255,255,255,0.08); border-radius: 99px; overflow: hidden; }
83
+ .status-fill { height: 100%; background: linear-gradient(90deg,#6ea8fe,#8de9fe); transition: width .3s; }
84
+ .status-mem { font-size: 11px; opacity: 0.6; margin-top: 6px; font-family: ui-monospace, monospace; }
85
+ """
86
+
87
+
88
+ def build_app() -> gr.Blocks:
89
+ with gr.Blocks(
90
+ theme=gr.themes.Soft(),
91
+ title="LTX 2.3 All-in-One",
92
+ css=_CUSTOM_CSS,
93
+ ) as app:
94
+ gr.Markdown("# ⚡ LTX 2.3 All-in-One")
95
+ with gr.Row():
96
+ with gr.Column(scale=1, min_width=200):
97
+ _render_sidebar()
98
+ with gr.Column(scale=4):
99
+ _render_mode_panels()
100
+ return app
101
+
102
+
103
+ def _render_sidebar() -> None:
104
+ gr.Markdown("### Modes")
105
+ for name, mode in modes.MODE_REGISTRY.items():
106
+ gr.Markdown(f"- {mode.icon} {mode.label}")
107
+ gr.Markdown("---\n### Models")
108
+ gr.Button("Unload all models", variant="secondary")
109
+
110
+
111
+ def _render_mode_panels() -> None:
112
+ with gr.Tabs():
113
+ for name, mode in modes.MODE_REGISTRY.items():
114
+ with gr.Tab(label=f"{mode.icon} {mode.label}"):
115
+ gr.Markdown(f"## {mode.label}")
116
+ gr.Markdown(f"_(Mode `{name}` form goes here — built in Task 22.)_")
117
+
118
+
119
+ if __name__ == "__main__":
120
+ app = build_app()
121
+ app.launch(server_name="0.0.0.0", server_port=7860)