aloatist commited on
Commit
97f0b87
·
verified ·
1 Parent(s): d0156c0

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +81 -0
app.py ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os
3
+ import subprocess
4
+ import time
5
+ from gradio.components import HTML
6
+ from huggingface_hub import hf_hub_download
7
+
8
+ # Tạo thư mục làm việc
9
+ WORK_DIR = "/app/ComfyUI"
10
+ if not os.path.exists(WORK_DIR):
11
+ os.makedirs(WORK_DIR)
12
+ subprocess.run(["git", "clone", "--depth", "1", "https://github.com/comfyanonymous/ComfyUI.git", WORK_DIR])
13
+
14
+ # Tải và cài đặt custom nodes (từ Dockerfile của bạn)
15
+ CUSTOM_NODES_DIR = os.path.join(WORK_DIR, "custom_nodes")
16
+ os.makedirs(CUSTOM_NODES_DIR, exist_ok=True)
17
+ custom_nodes = [
18
+ "https://github.com/ltdrdata/ComfyUI-Manager.git",
19
+ "https://github.com/Kosinkadink/ComfyUI-VideoHelperSuite.git",
20
+ "https://github.com/FizzleDorf/ComfyUI_FizzNodes.git",
21
+ "https://github.com/Stability-AI/stability-ComfyUI-nodes.git",
22
+ "https://github.com/EllangoK/ComfyUI-post-processing-nodes.git",
23
+ "https://github.com/TinyTerra/ComfyUI_tinyterraNodes.git",
24
+ "https://github.com/WASasquatch/was-node-suite-comfyui.git",
25
+ "https://github.com/WASasquatch/PowerNoiseSuite.git",
26
+ "https://github.com/Kosinkadink/ComfyUI-AnimateDiff-Evolved.git"
27
+ ]
28
+ for repo in custom_nodes:
29
+ repo_name = repo.split("/")[-1].replace(".git", "")
30
+ target_dir = os.path.join(CUSTOM_NODES_DIR, repo_name)
31
+ if not os.path.exists(target_dir):
32
+ subprocess.run(["git", "clone", "--depth", "1", repo, target_dir])
33
+
34
+ # Tải mô hình AnimateDiff
35
+ animate_diff_dir = os.path.join(CUSTOM_NODES_DIR, "ComfyUI-AnimateDiff-Evolved/models")
36
+ os.makedirs(animate_diff_dir, exist_ok=True)
37
+ for model in ["mm_sd_v15_v2.ckpt", "mm_sd_v15.ckpt"]:
38
+ model_path = os.path.join(animate_diff_dir, model)
39
+ if not os.path.exists(model_path):
40
+ subprocess.run(["wget", "-c", f"https://huggingface.co/guoyww/animatediff/resolve/main/{model}", "-P", animate_diff_dir])
41
+
42
+ # Tải mô hình WAN 2.1 I2V-14B-720P
43
+ MODEL_DIR = os.path.join(WORK_DIR, "models")
44
+ os.makedirs(MODEL_DIR, exist_ok=True)
45
+
46
+ def download_model(repo_id, filename, subfolder):
47
+ target_dir = os.path.join(MODEL_DIR, subfolder)
48
+ os.makedirs(target_dir, exist_ok=True)
49
+ file_path = os.path.join(target_dir, filename)
50
+ if not os.path.exists(file_path):
51
+ hf_hub_download(repo_id=repo_id, filename=filename, local_dir=target_dir)
52
+ print(f"Đã tải {filename} vào {target_dir}")
53
+
54
+ repo_id = "Comfy-Org/Wan_2.1_ComfyUI_repackaged"
55
+ download_model(repo_id, "wan2.1_i2v_720p_14B_fp8_e4m3fn.safetensors", "diffusion_models")
56
+ download_model(repo_id, "wan_2.1_vae.safetensors", "vae")
57
+ download_model(repo_id, "umt5_xxl_fp8_e4m3fn_scaled.safetensors", "text_encoders")
58
+ download_model(repo_id, "clip_vision_h.safetensors", "clip_vision")
59
+
60
+ # Khởi động ComfyUI
61
+ def start_comfyui():
62
+ subprocess.Popen(["python", "main.py", "--port", "7860", "--listen", "0.0.0.0", "--use-split-cross-attention"], cwd=WORK_DIR)
63
+ time.sleep(5)
64
+
65
+ start_comfyui()
66
+
67
+ # Nhúng giao diện
68
+ comfyui_interface = """
69
+ <iframe src="http://localhost:7860" width="100%" height="600px" style="border:none;"></iframe>
70
+ """
71
+
72
+ demo = gr.Interface(
73
+ fn=lambda x: "Dùng giao diện ComfyUI bên dưới",
74
+ inputs=gr.Textbox(label="Thông tin", value="ComfyUI với WAN 2.1 I2V-14B-720P"),
75
+ outputs=gr.Textbox(label="Trạng thái"),
76
+ title="ComfyUI Advanced - WAN 2.1 I2V",
77
+ description="Chạy workflow Image-to-Video 720P.",
78
+ additional_inputs=[HTML(comfyui_interface)]
79
+ )
80
+
81
+ demo.launch(server_name="0.0.0.0", server_port=7860)