Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -35,19 +35,14 @@ hf_hub_download(
|
|
35 |
|
36 |
def get_value_at_index(obj: Union[Sequence, Mapping], index: int) -> Any:
|
37 |
"""Returns the value at the given index of a sequence or mapping.
|
38 |
-
|
39 |
If the object is a sequence (like list or string), returns the value at the given index.
|
40 |
If the object is a mapping (like a dictionary), returns the value at the index-th key.
|
41 |
-
|
42 |
Some return a dictionary, in these cases, we look for the "results" key
|
43 |
-
|
44 |
Args:
|
45 |
obj (Union[Sequence, Mapping]): The object to retrieve the value from.
|
46 |
index (int): The index of the value to retrieve.
|
47 |
-
|
48 |
Returns:
|
49 |
Any: The value at the given index.
|
50 |
-
|
51 |
Raises:
|
52 |
IndexError: If the index is out of bounds for the object and the object is not a mapping.
|
53 |
"""
|
@@ -119,7 +114,6 @@ add_extra_model_paths()
|
|
119 |
|
120 |
def import_custom_nodes() -> None:
|
121 |
"""Find all custom nodes in the custom_nodes folder and add those node objects to NODE_CLASS_MAPPINGS
|
122 |
-
|
123 |
This function sets up a new asyncio event loop, initializes the PromptServer,
|
124 |
creates a PromptQueue, and initializes the custom nodes.
|
125 |
"""
|
@@ -140,11 +134,11 @@ def import_custom_nodes() -> None:
|
|
140 |
init_extra_nodes()
|
141 |
|
142 |
from nodes import NODE_CLASS_MAPPINGS
|
143 |
-
|
144 |
-
#
|
145 |
-
downloadandloadcogvideomodel = NODE_CLASS_MAPPINGS[
|
146 |
-
|
147 |
-
]()
|
148 |
# downloadandloadcogvideomodel_1 = downloadandloadcogvideomodel.loadmodel(
|
149 |
# model="THUDM/CogVideoX-5b",
|
150 |
# precision="bf16",
|
@@ -153,35 +147,34 @@ downloadandloadcogvideomodel = NODE_CLASS_MAPPINGS[
|
|
153 |
# attention_mode="sdpa",
|
154 |
# load_device="main_device",
|
155 |
# )
|
156 |
-
loadimage = NODE_CLASS_MAPPINGS["LoadImage"]()
|
157 |
-
cliploader = NODE_CLASS_MAPPINGS["CLIPLoader"]()
|
158 |
-
cliploader_20 = cliploader.load_clip(
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
)
|
163 |
-
emptylatentimage = NODE_CLASS_MAPPINGS["EmptyLatentImage"]()
|
164 |
|
165 |
-
cogvideotextencode = NODE_CLASS_MAPPINGS["CogVideoTextEncode"]()
|
166 |
-
cogvideosampler = NODE_CLASS_MAPPINGS["CogVideoSampler"]()
|
167 |
-
cogvideodecode = NODE_CLASS_MAPPINGS["CogVideoDecode"]()
|
168 |
-
reactorfaceswap = NODE_CLASS_MAPPINGS["ReActorFaceSwap"]()
|
169 |
-
cr_upscale_image = NODE_CLASS_MAPPINGS["CR Upscale Image"]()
|
170 |
-
vhs_videocombine = NODE_CLASS_MAPPINGS["VHS_VideoCombine"]()
|
171 |
|
172 |
-
#Add all the models that load a safetensors file
|
173 |
-
model_loaders = [cliploader_20]
|
174 |
# model_loaders = [downloadandloadcogvideomodel_1, cliploader_20]
|
175 |
|
176 |
-
# Check which models are valid and how to best load them
|
177 |
-
valid_models = [
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
]
|
182 |
|
183 |
-
#Finally loads the models
|
184 |
-
model_management.load_models_gpu(valid_models)
|
185 |
|
186 |
#Run ComfyUI Workflow
|
187 |
@spaces.GPU(duration=60)
|
@@ -192,11 +185,11 @@ def generate_video(positive_prompt, num_frames, input_image):
|
|
192 |
print("Input Image:", input_image)
|
193 |
|
194 |
with gr.Progress(track_tqdm=True):
|
195 |
-
|
196 |
with torch.inference_mode():
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
downloadandloadcogvideomodel_1 = downloadandloadcogvideomodel.loadmodel(
|
201 |
model="THUDM/CogVideoX-5b",
|
202 |
precision="bf16",
|
@@ -206,27 +199,29 @@ def generate_video(positive_prompt, num_frames, input_image):
|
|
206 |
load_device="main_device",
|
207 |
)
|
208 |
|
209 |
-
|
210 |
loadimage_8 = loadimage.load_image(image=input_image)
|
211 |
|
212 |
-
|
213 |
cliploader_20 = cliploader.load_clip(
|
214 |
clip_name="google_t5-v1_1-xxl_encoderonly-fp8_e4m3fn.safetensors",
|
215 |
type="sd3",
|
216 |
device="default",
|
217 |
)
|
218 |
|
219 |
-
|
220 |
emptylatentimage_161 = emptylatentimage.generate(
|
221 |
-
width=
|
|
|
|
|
222 |
)
|
223 |
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
|
231 |
for q in range(1):
|
232 |
cogvideotextencode_30 = cogvideotextencode.process(
|
@@ -245,7 +240,7 @@ def generate_video(positive_prompt, num_frames, input_image):
|
|
245 |
|
246 |
cogvideosampler_155 = cogvideosampler.process(
|
247 |
num_frames=num_frames,
|
248 |
-
steps=
|
249 |
cfg=6,
|
250 |
seed=random.randint(1, 2**64),
|
251 |
scheduler="CogVideoXDDIM",
|
@@ -258,8 +253,8 @@ def generate_video(positive_prompt, num_frames, input_image):
|
|
258 |
|
259 |
cogvideodecode_11 = cogvideodecode.decode(
|
260 |
enable_vae_tiling=False,
|
261 |
-
tile_sample_min_height=240
|
262 |
-
tile_sample_min_width=360
|
263 |
tile_overlap_factor_height=0.2,
|
264 |
tile_overlap_factor_width=0.2,
|
265 |
auto_tile_size=True,
|
@@ -330,4 +325,4 @@ if __name__ == "__main__":
|
|
330 |
outputs=[output_video]
|
331 |
)
|
332 |
|
333 |
-
app.launch(share=True)
|
|
|
35 |
|
36 |
def get_value_at_index(obj: Union[Sequence, Mapping], index: int) -> Any:
|
37 |
"""Returns the value at the given index of a sequence or mapping.
|
|
|
38 |
If the object is a sequence (like list or string), returns the value at the given index.
|
39 |
If the object is a mapping (like a dictionary), returns the value at the index-th key.
|
|
|
40 |
Some return a dictionary, in these cases, we look for the "results" key
|
|
|
41 |
Args:
|
42 |
obj (Union[Sequence, Mapping]): The object to retrieve the value from.
|
43 |
index (int): The index of the value to retrieve.
|
|
|
44 |
Returns:
|
45 |
Any: The value at the given index.
|
|
|
46 |
Raises:
|
47 |
IndexError: If the index is out of bounds for the object and the object is not a mapping.
|
48 |
"""
|
|
|
114 |
|
115 |
def import_custom_nodes() -> None:
|
116 |
"""Find all custom nodes in the custom_nodes folder and add those node objects to NODE_CLASS_MAPPINGS
|
|
|
117 |
This function sets up a new asyncio event loop, initializes the PromptServer,
|
118 |
creates a PromptQueue, and initializes the custom nodes.
|
119 |
"""
|
|
|
134 |
init_extra_nodes()
|
135 |
|
136 |
from nodes import NODE_CLASS_MAPPINGS
|
137 |
+
|
138 |
+
#TO be added to "model_loaders" as it loads a model
|
139 |
+
# downloadandloadcogvideomodel = NODE_CLASS_MAPPINGS[
|
140 |
+
# "DownloadAndLoadCogVideoModel"
|
141 |
+
# ]()
|
142 |
# downloadandloadcogvideomodel_1 = downloadandloadcogvideomodel.loadmodel(
|
143 |
# model="THUDM/CogVideoX-5b",
|
144 |
# precision="bf16",
|
|
|
147 |
# attention_mode="sdpa",
|
148 |
# load_device="main_device",
|
149 |
# )
|
150 |
+
# loadimage = NODE_CLASS_MAPPINGS["LoadImage"]()
|
151 |
+
# cliploader = NODE_CLASS_MAPPINGS["CLIPLoader"]()
|
152 |
+
# cliploader_20 = cliploader.load_clip(
|
153 |
+
# clip_name="t5/google_t5-v1_1-xxl_encoderonly-fp8_e4m3fn.safetensors",
|
154 |
+
# type="sd3",
|
155 |
+
# device="default",
|
156 |
+
# )
|
157 |
+
# emptylatentimage = NODE_CLASS_MAPPINGS["EmptyLatentImage"]()
|
158 |
|
159 |
+
# cogvideotextencode = NODE_CLASS_MAPPINGS["CogVideoTextEncode"]()
|
160 |
+
# cogvideosampler = NODE_CLASS_MAPPINGS["CogVideoSampler"]()
|
161 |
+
# cogvideodecode = NODE_CLASS_MAPPINGS["CogVideoDecode"]()
|
162 |
+
# reactorfaceswap = NODE_CLASS_MAPPINGS["ReActorFaceSwap"]()
|
163 |
+
# cr_upscale_image = NODE_CLASS_MAPPINGS["CR Upscale Image"]()
|
164 |
+
# vhs_videocombine = NODE_CLASS_MAPPINGS["VHS_VideoCombine"]()
|
165 |
|
166 |
+
# #Add all the models that load a safetensors file
|
|
|
167 |
# model_loaders = [downloadandloadcogvideomodel_1, cliploader_20]
|
168 |
|
169 |
+
# # Check which models are valid and how to best load them
|
170 |
+
# valid_models = [
|
171 |
+
# getattr(loader[0], 'patcher', loader[0])
|
172 |
+
# for loader in model_loaders
|
173 |
+
# if not isinstance(loader[0], dict) and not isinstance(getattr(loader[0], 'patcher', None), dict)
|
174 |
+
# ]
|
175 |
|
176 |
+
# #Finally loads the models
|
177 |
+
# model_management.load_models_gpu(valid_models)
|
178 |
|
179 |
#Run ComfyUI Workflow
|
180 |
@spaces.GPU(duration=60)
|
|
|
185 |
print("Input Image:", input_image)
|
186 |
|
187 |
with gr.Progress(track_tqdm=True):
|
188 |
+
import_custom_nodes()
|
189 |
with torch.inference_mode():
|
190 |
+
downloadandloadcogvideomodel = NODE_CLASS_MAPPINGS[
|
191 |
+
"DownloadAndLoadCogVideoModel"
|
192 |
+
]()
|
193 |
downloadandloadcogvideomodel_1 = downloadandloadcogvideomodel.loadmodel(
|
194 |
model="THUDM/CogVideoX-5b",
|
195 |
precision="bf16",
|
|
|
199 |
load_device="main_device",
|
200 |
)
|
201 |
|
202 |
+
loadimage = NODE_CLASS_MAPPINGS["LoadImage"]()
|
203 |
loadimage_8 = loadimage.load_image(image=input_image)
|
204 |
|
205 |
+
cliploader = NODE_CLASS_MAPPINGS["CLIPLoader"]()
|
206 |
cliploader_20 = cliploader.load_clip(
|
207 |
clip_name="google_t5-v1_1-xxl_encoderonly-fp8_e4m3fn.safetensors",
|
208 |
type="sd3",
|
209 |
device="default",
|
210 |
)
|
211 |
|
212 |
+
emptylatentimage = NODE_CLASS_MAPPINGS["EmptyLatentImage"]()
|
213 |
emptylatentimage_161 = emptylatentimage.generate(
|
214 |
+
width=360, #reduce this to avoid OOM error
|
215 |
+
height=240, #reduce this to avoid OOM error
|
216 |
+
batch_size=1 #reduce this to avoid OOM error
|
217 |
)
|
218 |
|
219 |
+
cogvideotextencode = NODE_CLASS_MAPPINGS["CogVideoTextEncode"]()
|
220 |
+
cogvideosampler = NODE_CLASS_MAPPINGS["CogVideoSampler"]()
|
221 |
+
cogvideodecode = NODE_CLASS_MAPPINGS["CogVideoDecode"]()
|
222 |
+
reactorfaceswap = NODE_CLASS_MAPPINGS["ReActorFaceSwap"]()
|
223 |
+
cr_upscale_image = NODE_CLASS_MAPPINGS["CR Upscale Image"]()
|
224 |
+
vhs_videocombine = NODE_CLASS_MAPPINGS["VHS_VideoCombine"]()
|
225 |
|
226 |
for q in range(1):
|
227 |
cogvideotextencode_30 = cogvideotextencode.process(
|
|
|
240 |
|
241 |
cogvideosampler_155 = cogvideosampler.process(
|
242 |
num_frames=num_frames,
|
243 |
+
steps=30, #reduce this to avoid OOM error
|
244 |
cfg=6,
|
245 |
seed=random.randint(1, 2**64),
|
246 |
scheduler="CogVideoXDDIM",
|
|
|
253 |
|
254 |
cogvideodecode_11 = cogvideodecode.decode(
|
255 |
enable_vae_tiling=False,
|
256 |
+
tile_sample_min_height=240,#reduce this to avoid OOM error
|
257 |
+
tile_sample_min_width=360,#reduce this to avoid OOM error
|
258 |
tile_overlap_factor_height=0.2,
|
259 |
tile_overlap_factor_width=0.2,
|
260 |
auto_tile_size=True,
|
|
|
325 |
outputs=[output_video]
|
326 |
)
|
327 |
|
328 |
+
app.launch(share=True)
|