daquanzhou commited on
Commit
1e63e86
β€’
1 Parent(s): 6e26bf4

add app, rm Dockerfile

Browse files
Dockerfile DELETED
@@ -1,50 +0,0 @@
1
- FROM nvidia/cuda:11.8.0-cudnn8-runtime-ubuntu22.04
2
-
3
- ENV DEBIAN_FRONTEND=noninteractive \
4
- TZ=America/Los_Angeles
5
-
6
- ARG USE_PERSISTENT_DATA
7
-
8
- RUN apt-get update && apt-get install -y \
9
- git \
10
- make build-essential libssl-dev zlib1g-dev \
11
- libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm \
12
- libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev git-lfs \
13
- ffmpeg libsm6 libxext6 cmake libgl1-mesa-glx \
14
- && rm -rf /var/lib/apt/lists/* \
15
- && git lfs install
16
-
17
- WORKDIR /code
18
-
19
- COPY ./requirements.txt /code/requirements.txt
20
-
21
- # User
22
- RUN useradd -m -u 1000 user
23
- USER user
24
- ENV HOME=/home/user \
25
- PATH=/home/user/.local/bin:$PATH
26
-
27
- # Pyenv
28
- RUN curl https://pyenv.run | bash
29
- ENV PATH=$HOME/.pyenv/shims:$HOME/.pyenv/bin:$PATH
30
-
31
- ARG PYTHON_VERSION=3.9.17
32
- # Python
33
- RUN pyenv install $PYTHON_VERSION && \
34
- pyenv global $PYTHON_VERSION && \
35
- pyenv rehash && \
36
- pip install --no-cache-dir --upgrade pip setuptools wheel && \
37
- pip install --no-cache-dir \
38
- datasets \
39
- huggingface-hub "protobuf<4" "click<8.1"
40
-
41
- RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
42
-
43
- # Set the working directory to /data if USE_PERSISTENT_DATA is set, otherwise set to $HOME/app
44
- WORKDIR $HOME/app
45
-
46
- # Copy the current directory contents into the container at $HOME/app setting the owner to the user
47
- COPY --chown=user . $HOME/app
48
-
49
- # Checkpoints
50
- CMD ["python", "main.py", "--listen", "0.0.0.0", "--port", "7860", "--output-directory", "${USE_PERSISTENT_DATA:+/data/}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obj: Union[Sequence, Mapping], index: int) -> Any:
9
+ """Returns the value at the given index of a sequence or mapping.
10
+
11
+ If the object is a sequence (like list or string), returns the value at the given index.
12
+ If the object is a mapping (like a dictionary), returns the value at the index-th key.
13
+
14
+ Some return a dictionary, in these cases, we look for the "results" key
15
+
16
+ Args:
17
+ obj (Union[Sequence, Mapping]): The object to retrieve the value from.
18
+ index (int): The index of the value to retrieve.
19
+
20
+ Returns:
21
+ Any: The value at the given index.
22
+
23
+ Raises:
24
+ IndexError: If the index is out of bounds for the object and the object is not a mapping.
25
+ """
26
+ try:
27
+ return obj[index]
28
+ except KeyError:
29
+ return obj["result"][index]
30
+
31
+
32
+ def find_path(name: str, path: str = None) -> str:
33
+ """
34
+ Recursively looks at parent folders starting from the given path until it finds the given name.
35
+ Returns the path as a Path object if found, or None otherwise.
36
+ """
37
+ # If no path is given, use the current working directory
38
+ if path is None:
39
+ path = os.getcwd()
40
+
41
+ # Check if the current directory contains the name
42
+ if name in os.listdir(path):
43
+ path_name = os.path.join(path, name)
44
+ print(f"{name} found: {path_name}")
45
+ return path_name
46
+
47
+ # Get the parent directory
48
+ parent_directory = os.path.dirname(path)
49
+
50
+ # If the parent directory is the same as the current directory, we've reached the root and stop the search
51
+ if parent_directory == path:
52
+ return None
53
+
54
+ # Recursively call the function with the parent directory
55
+ return find_path(name, parent_directory)
56
+
57
+
58
+ def add_comfyui_directory_to_sys_path() -> None:
59
+ """
60
+ Add 'ComfyUI' to the sys.path
61
+ """
62
+ comfyui_path = find_path("ComfyUI")
63
+ if comfyui_path is not None and os.path.isdir(comfyui_path):
64
+ sys.path.append(comfyui_path)
65
+ print(f"'{comfyui_path}' added to sys.path")
66
+
67
+
68
+ def add_extra_model_paths() -> None:
69
+ """
70
+ Parse the optional extra_model_paths.yaml file and add the parsed paths to the sys.path.
71
+ """
72
+ from main import load_extra_path_config
73
+
74
+ extra_model_paths = find_path("extra_model_paths.yaml")
75
+
76
+ if extra_model_paths is not None:
77
+ load_extra_path_config(extra_model_paths)
78
+ else:
79
+ print("Could not find the extra_model_paths config file.")
80
+
81
+
82
+ add_comfyui_directory_to_sys_path()
83
+ add_extra_model_paths()
84
+
85
+
86
+ def import_custom_nodes() -> None:
87
+ """Find all custom nodes in the custom_nodes folder and add those node objects to NODE_CLASS_MAPPINGS
88
+
89
+ This function sets up a new asyncio event loop, initializes the PromptServer,
90
+ creates a PromptQueue, and initializes the custom nodes.
91
+ """
92
+ import asyncio
93
+ import execution
94
+ from nodes import init_custom_nodes
95
+ import server
96
+
97
+ # Creating a new event loop and setting it as the default loop
98
+ loop = asyncio.new_event_loop()
99
+ asyncio.set_event_loop(loop)
100
+
101
+ # Creating an instance of PromptServer with the loop
102
+ server_instance = server.PromptServer(loop)
103
+ execution.PromptQueue(server_instance)
104
+
105
+ # Initializing custom nodes
106
+ init_custom_nodes()
107
+
108
+
109
+ from nodes import (
110
+ EmptyLatentImage,
111
+ CheckpointLoaderSimple,
112
+ NODE_CLASS_MAPPINGS,
113
+ KSamplerAdvanced,
114
+ MagicAlbum3DGaussianNoise,
115
+ CLIPTextEncode,
116
+ VAELoader,
117
+ VAEDecode,
118
+ )
119
+
120
+
121
+
122
+
123
+
124
+
125
+ class MagicMeController:
126
+ def __init__(self):
127
+ with torch.inference_mode():
128
+ vaeloader = VAELoader()
129
+ self.vaeloader_2 = vaeloader.load_vae(
130
+ vae_name="vae-ft-mse-840000-ema-pruned.safetensors"
131
+ )
132
+
133
+ checkpointloadersimple = CheckpointLoaderSimple()
134
+ self.checkpointloadersimple_32 = checkpointloadersimple.load_checkpoint(
135
+ ckpt_name="realisticVision_v51.safetensors"
136
+ )
137
+
138
+
139
+ ultralyticsdetectorprovider = NODE_CLASS_MAPPINGS[
140
+ "UltralyticsDetectorProvider"
141
+ ]()
142
+ self.ultralyticsdetectorprovider_75 = ultralyticsdetectorprovider.doit(
143
+ model_name="bbox/face_yolov8m.pt"
144
+ )
145
+
146
+ samloader = NODE_CLASS_MAPPINGS["SAMLoader"]()
147
+ self.samloader_78 = samloader.load_model(
148
+ model_name="sam_vit_b_01ec64.pth", device_mode="AUTO"
149
+ )
150
+
151
+ ade_animatediffuniformcontextoptions = NODE_CLASS_MAPPINGS[
152
+ "ADE_AnimateDiffUniformContextOptions"
153
+ ]()
154
+ self.ade_animatediffuniformcontextoptions_102 = (
155
+ ade_animatediffuniformcontextoptions.create_options(
156
+ context_length=16, context_stride=1, context_overlap=2, closed_loop=False,
157
+ context_schedule="uniform", fuse_method="flat"
158
+ )
159
+ )
160
+
161
+ upscalemodelloader = NODE_CLASS_MAPPINGS["UpscaleModelLoader"]()
162
+ self.upscalemodelloader_157 = upscalemodelloader.load_model(
163
+ model_name="4xUltrasharpV10.pt"
164
+ )
165
+
166
+ ade_animatediffloraloader = NODE_CLASS_MAPPINGS["ADE_AnimateDiffLoRALoader"]()
167
+ self.ade_animatediffloraloader_196 = ade_animatediffloraloader.load_motion_lora(
168
+ lora_name="v2_lora_ZoomIn.ckpt", strength=0.6
169
+ )
170
+
171
+ impactint = NODE_CLASS_MAPPINGS["ImpactInt"]()
172
+ self.impactint_204 = impactint.doit(value=16)
173
+
174
+ self.ade_animatediffloaderwithcontext = NODE_CLASS_MAPPINGS[
175
+ "ADE_AnimateDiffLoaderWithContext"
176
+ ]()
177
+ self.freeu_v2 = NODE_CLASS_MAPPINGS["FreeU_V2"]()
178
+ self.tobasicpipe = NODE_CLASS_MAPPINGS["ToBasicPipe"]()
179
+ self.frombasicpipe = NODE_CLASS_MAPPINGS["FromBasicPipe"]()
180
+ self.bnk_getsigma = NODE_CLASS_MAPPINGS["BNK_GetSigma"]()
181
+ self.emptylatentimage = EmptyLatentImage()
182
+ self.magicalbum3dgaussiannoise = MagicAlbum3DGaussianNoise()
183
+ self.bnk_injectnoise = NODE_CLASS_MAPPINGS["BNK_InjectNoise"]()
184
+ self.ksampleradvanced = KSamplerAdvanced()
185
+ self.vaedecode = VAEDecode()
186
+ self.vhs_videocombine = NODE_CLASS_MAPPINGS["VHS_VideoCombine"]()
187
+ self.impactsimpledetectorsegs_for_ad = NODE_CLASS_MAPPINGS[
188
+ "ImpactSimpleDetectorSEGS_for_AD"
189
+ ]()
190
+ self.segsdetailerforanimatediff = NODE_CLASS_MAPPINGS["SEGSDetailerForAnimateDiff"]()
191
+ self.segspaste = NODE_CLASS_MAPPINGS["SEGSPaste"]()
192
+ self.segspreview = NODE_CLASS_MAPPINGS["SEGSPreview"]()
193
+ self.ultimatesdupscale = NODE_CLASS_MAPPINGS["UltimateSDUpscale"]()
194
+ self.imagecasharpening = NODE_CLASS_MAPPINGS["ImageCASharpening+"]()
195
+
196
+ def run_once(self, prompt_text_box, negative_prompt_text_box):
197
+ with torch.inference_mode():
198
+ cliptextencode = CLIPTextEncode()
199
+ cliptextencode_6 = cliptextencode.encode(
200
+ text="(deformed iris, deformed pupils, semi-realistic, cgi, 3d, render, sketch, cartoon, drawing, anime), text, cropped, out of frame, worst quality, low quality, jpeg artifacts, ugly, duplicate, morbid, mutilated, extra fingers, mutated hands, poorly drawn hands, poorly drawn face, mutation, deformed, blurry, dehydrated, bad anatomy, bad proportions, extra limbs, cloned face, disfigured, gross proportions, malformed limbs, missing arms, missing legs, extra arms, extra legs, fused fingers, too many fingers, long neck, UnrealisticDream",
201
+ clip=get_value_at_index(self.checkpointloadersimple_32, 1),
202
+ )
203
+ cliptextencode_274 = cliptextencode.encode(
204
+ text="a photo of embedding:altman man in superman costume in the outer space, stars in the background",
205
+ clip=get_value_at_index(self.checkpointloadersimple_32, 1),
206
+ )
207
+ ade_animatediffloaderwithcontext_261 = (
208
+ self.ade_animatediffloaderwithcontext.load_mm_and_inject_params(
209
+ model_name="mm_sd_v15_v2.ckpt",
210
+ beta_schedule="autoselect",
211
+ motion_scale=1,
212
+ apply_v2_models_properly=True,
213
+ model=get_value_at_index(self.checkpointloadersimple_32, 0),
214
+ context_options=get_value_at_index(
215
+ self.ade_animatediffuniformcontextoptions_102, 0
216
+ ),
217
+ motion_lora=get_value_at_index(self.ade_animatediffloraloader_196, 0),
218
+ )
219
+ )
220
+
221
+ freeu_v2_151 = self.freeu_v2.patch(
222
+ b1=1.1,
223
+ b2=1.2,
224
+ s1=0.9,
225
+ s2=0.4,
226
+ model=get_value_at_index(ade_animatediffloaderwithcontext_261, 0),
227
+ )
228
+
229
+ tobasicpipe_42 = self.tobasicpipe.doit(
230
+ model=get_value_at_index(freeu_v2_151, 0),
231
+ clip=get_value_at_index(self.checkpointloadersimple_32, 1),
232
+ vae=get_value_at_index(self.vaeloader_2, 0),
233
+ positive=get_value_at_index(cliptextencode_274, 0),
234
+ negative=get_value_at_index(cliptextencode_6, 0),
235
+ )
236
+
237
+ frombasicpipe_52 = self.frombasicpipe.doit(
238
+ basic_pipe=get_value_at_index(tobasicpipe_42, 0)
239
+ )
240
+
241
+ bnk_getsigma_254 = self.bnk_getsigma.calc_sigma(
242
+ sampler_name="dpmpp_2m",
243
+ scheduler="karras",
244
+ steps=20,
245
+ start_at_step=0,
246
+ end_at_step=20,
247
+ model=get_value_at_index(frombasicpipe_52, 0),
248
+ )
249
+
250
+ emptylatentimage_223 = self.emptylatentimage.generate(
251
+ width=512, height=512, batch_size=get_value_at_index(self.impactint_204, 0)
252
+ )
253
+
254
+ magicalbum3dgaussiannoise_262 = self.magicalbum3dgaussiannoise.generate(
255
+ width=512,
256
+ height=512,
257
+ batch_size=get_value_at_index(self.impactint_204, 0),
258
+ seed=random.randint(1, 2**64),
259
+ cov_factor=0.15,
260
+ )
261
+
262
+ bnk_injectnoise_253 = self.bnk_injectnoise.inject_noise(
263
+ strength=get_value_at_index(bnk_getsigma_254, 0),
264
+ latents=get_value_at_index(emptylatentimage_223, 0),
265
+ noise=get_value_at_index(magicalbum3dgaussiannoise_262, 0),
266
+ )
267
+
268
+ ksampleradvanced_248 = self.ksampleradvanced.sample(
269
+ add_noise="disable",
270
+ noise_seed=random.randint(1, 2**64),
271
+ steps=20,
272
+ cfg=8,
273
+ sampler_name="dpmpp_2m",
274
+ scheduler="karras",
275
+ start_at_step=0,
276
+ end_at_step=20,
277
+ return_with_leftover_noise="disable",
278
+ model=get_value_at_index(frombasicpipe_52, 0),
279
+ positive=get_value_at_index(frombasicpipe_52, 3),
280
+ negative=get_value_at_index(frombasicpipe_52, 4),
281
+ latent_image=get_value_at_index(bnk_injectnoise_253, 0),
282
+ )
283
+
284
+ vaedecode_10 = self.vaedecode.decode(
285
+ samples=get_value_at_index(ksampleradvanced_248, 0),
286
+ vae=get_value_at_index(frombasicpipe_52, 2),
287
+ )
288
+
289
+ vhs_videocombine_35 = self.vhs_videocombine.combine_video(
290
+ frame_rate=8,
291
+ loop_count=0,
292
+ filename_prefix="orig",
293
+ format="video/h264-mp4",
294
+ pingpong=False,
295
+ save_output=False,
296
+ images=get_value_at_index(vaedecode_10, 0),
297
+ unique_id=2001771405939721385,
298
+ )
299
+
300
+ impactsimpledetectorsegs_for_ad_156 = self.impactsimpledetectorsegs_for_ad.doit(
301
+ bbox_threshold=0.5,
302
+ bbox_dilation=0,
303
+ crop_factor=3,
304
+ drop_size=10,
305
+ sub_threshold=0.5,
306
+ sub_dilation=0,
307
+ sub_bbox_expansion=0,
308
+ sam_mask_hint_threshold=0.7,
309
+ masking_mode="Pivot SEGS",
310
+ segs_pivot="Combined mask",
311
+ bbox_detector=get_value_at_index(self.ultralyticsdetectorprovider_75, 0),
312
+ image_frames=get_value_at_index(vaedecode_10, 0),
313
+ sam_model_opt=get_value_at_index(self.samloader_78, 0),
314
+ )
315
+
316
+ segsdetailerforanimatediff_41 = self.segsdetailerforanimatediff.doit(
317
+ guide_size=512,
318
+ guide_size_for=False,
319
+ max_size=512,
320
+ seed=random.randint(1, 2**64),
321
+ steps=20,
322
+ cfg=8,
323
+ sampler_name="euler",
324
+ scheduler="normal",
325
+ denoise=0.8,
326
+ refiner_ratio=0.2,
327
+ image_frames=get_value_at_index(vaedecode_10, 0),
328
+ segs=get_value_at_index(impactsimpledetectorsegs_for_ad_156, 0),
329
+ basic_pipe=get_value_at_index(tobasicpipe_42, 0),
330
+ )
331
+
332
+ segspaste_49 = self.segspaste.doit(
333
+ feather=5,
334
+ alpha=255,
335
+ image=get_value_at_index(vaedecode_10, 0),
336
+ segs=get_value_at_index(segsdetailerforanimatediff_41, 0),
337
+ )
338
+
339
+ vhs_videocombine_51 = self.vhs_videocombine.combine_video(
340
+ frame_rate=8,
341
+ loop_count=0,
342
+ filename_prefix="face_detailer",
343
+ format="video/h264-mp4",
344
+ pingpong=False,
345
+ save_output=False,
346
+ images=get_value_at_index(segspaste_49, 0),
347
+ unique_id=7104489750160636615,
348
+ )
349
+
350
+ # segspreview_101 = self.segspreview.doit(
351
+ # alpha_mode=True,
352
+ # min_alpha=0.2,
353
+ # segs=get_value_at_index(impactsimpledetectorsegs_for_ad_156, 0),
354
+ # )
355
+
356
+ frombasicpipe_175 = self.frombasicpipe.doit(
357
+ basic_pipe=get_value_at_index(tobasicpipe_42, 0)
358
+ )
359
+
360
+ ultimatesdupscale_172 = self.ultimatesdupscale.upscale(
361
+ upscale_by=2,
362
+ seed=random.randint(1, 2**64),
363
+ steps=20,
364
+ cfg=8,
365
+ sampler_name="euler",
366
+ scheduler="normal",
367
+ denoise=0.2,
368
+ mode_type="Linear",
369
+ tile_width=512,
370
+ tile_height=512,
371
+ mask_blur=8,
372
+ tile_padding=32,
373
+ seam_fix_mode="None",
374
+ seam_fix_denoise=1,
375
+ seam_fix_width=64,
376
+ seam_fix_mask_blur=8,
377
+ seam_fix_padding=16,
378
+ force_uniform_tiles=True,
379
+ tiled_decode=False,
380
+ image=get_value_at_index(segspaste_49, 0),
381
+ model=get_value_at_index(frombasicpipe_175, 0),
382
+ positive=get_value_at_index(frombasicpipe_175, 3),
383
+ negative=get_value_at_index(frombasicpipe_175, 4),
384
+ vae=get_value_at_index(frombasicpipe_175, 2),
385
+ upscale_model=get_value_at_index(self.upscalemodelloader_157, 0),
386
+ )
387
+
388
+ imagecasharpening_183 = self.imagecasharpening.execute(
389
+ amount=0.2, image=get_value_at_index(ultimatesdupscale_172, 0)
390
+ )
391
+
392
+ vhs_videocombine_176 = self.vhs_videocombine.combine_video(
393
+ frame_rate=8,
394
+ loop_count=0,
395
+ filename_prefix="SR",
396
+ format="video/h265-mp4",
397
+ pingpong=False,
398
+ save_output=True,
399
+ images=get_value_at_index(imagecasharpening_183, 0),
400
+ unique_id=5059112282155244564,
401
+ )
402
+
403
+
404
+ def main():
405
+ import_custom_nodes()
406
+ if __name__ == "__main__":
407
+ main()
408
+ c = MagicMeController()
409
+ c.run_once(None,None)
{app β†’ app_setting}/app_settings.py RENAMED
File without changes
{app β†’ app_setting}/user_manager.py RENAMED
File without changes
server.py CHANGED
@@ -30,7 +30,7 @@ from comfy.cli_args import args
30
  import comfy.utils
31
  import comfy.model_management
32
 
33
- from app.user_manager import UserManager
34
 
35
  class BinaryEventTypes:
36
  PREVIEW_IMAGE = 1
 
30
  import comfy.utils
31
  import comfy.model_management
32
 
33
+ from app_setting.user_manager import UserManager
34
 
35
  class BinaryEventTypes:
36
  PREVIEW_IMAGE = 1