bug fix
Browse files
app.py
CHANGED
|
@@ -69,7 +69,7 @@ def get_modelscope_pipeline(
|
|
| 69 |
lora.merge_and_unload()
|
| 70 |
pipe.unet = lora
|
| 71 |
|
| 72 |
-
|
| 73 |
|
| 74 |
return pipe
|
| 75 |
|
|
@@ -136,7 +136,7 @@ def get_animatediff_pipeline(
|
|
| 136 |
lora.merge_and_unload()
|
| 137 |
pipe.unet = lora
|
| 138 |
|
| 139 |
-
|
| 140 |
return pipe
|
| 141 |
|
| 142 |
|
|
@@ -146,42 +146,42 @@ pipe_dict = {
|
|
| 146 |
"AnimateDiff (RealisticVision)": {"WebVid": None, "LAION-aes": None},
|
| 147 |
"AnimateDiff (epiCRealism)": {"WebVid": None, "LAION-aes": None},
|
| 148 |
}
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
def init_pipelines():
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
|
| 182 |
@spaces.GPU(duration=120)
|
| 183 |
def infer(
|
| 184 |
-
base_model, variant, prompt, num_inference_steps=4, seed=0, randomize_seed=True,
|
| 185 |
):
|
| 186 |
# if pipe_dict[base_model][variant] is None:
|
| 187 |
# if base_model == "ModelScope T2V":
|
|
@@ -206,46 +206,47 @@ def infer(
|
|
| 206 |
# )
|
| 207 |
# else:
|
| 208 |
# raise ValueError(f"Unknown base_model {base_model}")
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
|
| 242 |
-
pipe_dict[base_model][variant] = pipe_dict[base_model][variant].to(device)
|
| 243 |
if randomize_seed:
|
| 244 |
seed = random.randint(0, MAX_SEED)
|
| 245 |
|
| 246 |
generator = torch.Generator("cpu").manual_seed(seed)
|
| 247 |
|
| 248 |
-
|
|
|
|
| 249 |
prompt=prompt,
|
| 250 |
num_frames=16,
|
| 251 |
guidance_scale=1.0,
|
|
@@ -265,7 +266,7 @@ def infer(
|
|
| 265 |
fps=7,
|
| 266 |
)
|
| 267 |
print(f"Saved to {save_path}")
|
| 268 |
-
pipe_dict[base_model][variant] = pipe_dict[base_model][variant].to("cpu")
|
| 269 |
return save_path, seed
|
| 270 |
|
| 271 |
|
|
@@ -276,7 +277,7 @@ examples = [
|
|
| 276 |
"Aerial uhd 4k view. mid-air flight over fresh and clean mountain river at sunny summer morning. Green trees and sun rays on horizon. Direct on sun.",
|
| 277 |
4
|
| 278 |
],
|
| 279 |
-
["ModelScope T2V", "Anime", "Timelapse misty mountain landscape"],
|
| 280 |
[
|
| 281 |
"ModelScope T2V",
|
| 282 |
"WebVid",
|
|
@@ -338,7 +339,7 @@ variants = {
|
|
| 338 |
def update_variant(rs):
|
| 339 |
return gr.update(choices=variants[rs], value=None)
|
| 340 |
|
| 341 |
-
init_pipelines()
|
| 342 |
|
| 343 |
with gr.Blocks(css=css) as demo:
|
| 344 |
|
|
|
|
| 69 |
lora.merge_and_unload()
|
| 70 |
pipe.unet = lora
|
| 71 |
|
| 72 |
+
pipe = pipe.to(device)
|
| 73 |
|
| 74 |
return pipe
|
| 75 |
|
|
|
|
| 136 |
lora.merge_and_unload()
|
| 137 |
pipe.unet = lora
|
| 138 |
|
| 139 |
+
pipe = pipe.to(device)
|
| 140 |
return pipe
|
| 141 |
|
| 142 |
|
|
|
|
| 146 |
"AnimateDiff (RealisticVision)": {"WebVid": None, "LAION-aes": None},
|
| 147 |
"AnimateDiff (epiCRealism)": {"WebVid": None, "LAION-aes": None},
|
| 148 |
}
|
| 149 |
+
cache_pipeline = {
|
| 150 |
+
"base_model": None,
|
| 151 |
+
"variant": None,
|
| 152 |
+
"pipeline": None,
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
# def init_pipelines():
|
| 156 |
+
# for base_model in variants.keys():
|
| 157 |
+
# for variant in variants[base_model]:
|
| 158 |
+
# if pipe_dict[base_model][variant] is None:
|
| 159 |
+
# if base_model == "ModelScope T2V":
|
| 160 |
+
# pipe_dict[base_model][variant] = get_modelscope_pipeline(mcm_variant=variant)
|
| 161 |
+
# elif base_model == "AnimateDiff (SD1.5)":
|
| 162 |
+
# pipe_dict[base_model][variant] = get_animatediff_pipeline(
|
| 163 |
+
# real_variant=None,
|
| 164 |
+
# motion_module_path="guoyww/animatediff-motion-adapter-v1-5-2",
|
| 165 |
+
# mcm_variant=variant,
|
| 166 |
+
# )
|
| 167 |
+
# elif base_model == "AnimateDiff (RealisticVision)":
|
| 168 |
+
# pipe_dict[base_model][variant] = get_animatediff_pipeline(
|
| 169 |
+
# real_variant="realvision",
|
| 170 |
+
# motion_module_path="guoyww/animatediff-motion-adapter-v1-5-2",
|
| 171 |
+
# mcm_variant=variant,
|
| 172 |
+
# )
|
| 173 |
+
# elif base_model == "AnimateDiff (epiCRealism)":
|
| 174 |
+
# pipe_dict[base_model][variant] = get_animatediff_pipeline(
|
| 175 |
+
# real_variant="epicrealism",
|
| 176 |
+
# motion_module_path="guoyww/animatediff-motion-adapter-v1-5-2",
|
| 177 |
+
# mcm_variant=variant,
|
| 178 |
+
# )
|
| 179 |
+
# else:
|
| 180 |
+
# raise ValueError(f"Unknown base_model {base_model}")
|
| 181 |
|
| 182 |
@spaces.GPU(duration=120)
|
| 183 |
def infer(
|
| 184 |
+
base_model, variant, prompt, num_inference_steps=4, seed=0, randomize_seed=True,
|
| 185 |
):
|
| 186 |
# if pipe_dict[base_model][variant] is None:
|
| 187 |
# if base_model == "ModelScope T2V":
|
|
|
|
| 206 |
# )
|
| 207 |
# else:
|
| 208 |
# raise ValueError(f"Unknown base_model {base_model}")
|
| 209 |
+
if (
|
| 210 |
+
cache_pipeline["base_model"] == base_model
|
| 211 |
+
and cache_pipeline["variant"] == variant
|
| 212 |
+
):
|
| 213 |
+
pass
|
| 214 |
+
else:
|
| 215 |
+
if base_model == "ModelScope T2V":
|
| 216 |
+
pipeline = get_modelscope_pipeline(mcm_variant=variant)
|
| 217 |
+
elif base_model == "AnimateDiff (SD1.5)":
|
| 218 |
+
pipeline = get_animatediff_pipeline(
|
| 219 |
+
real_variant=None,
|
| 220 |
+
motion_module_path="guoyww/animatediff-motion-adapter-v1-5-2",
|
| 221 |
+
mcm_variant=variant,
|
| 222 |
+
)
|
| 223 |
+
elif base_model == "AnimateDiff (RealisticVision)":
|
| 224 |
+
pipeline = get_animatediff_pipeline(
|
| 225 |
+
real_variant="realvision",
|
| 226 |
+
motion_module_path="guoyww/animatediff-motion-adapter-v1-5-2",
|
| 227 |
+
mcm_variant=variant,
|
| 228 |
+
)
|
| 229 |
+
elif base_model == "AnimateDiff (epiCRealism)":
|
| 230 |
+
pipeline = get_animatediff_pipeline(
|
| 231 |
+
real_variant="epicrealism",
|
| 232 |
+
motion_module_path="guoyww/animatediff-motion-adapter-v1-5-2",
|
| 233 |
+
mcm_variant=variant,
|
| 234 |
+
)
|
| 235 |
+
else:
|
| 236 |
+
raise ValueError(f"Unknown base_model {base_model}")
|
| 237 |
|
| 238 |
+
cache_pipeline["base_model"] = base_model
|
| 239 |
+
cache_pipeline["variant"] = variant
|
| 240 |
+
cache_pipeline["pipeline"] = pipeline
|
| 241 |
|
| 242 |
+
# pipe_dict[base_model][variant] = pipe_dict[base_model][variant].to(device)
|
| 243 |
if randomize_seed:
|
| 244 |
seed = random.randint(0, MAX_SEED)
|
| 245 |
|
| 246 |
generator = torch.Generator("cpu").manual_seed(seed)
|
| 247 |
|
| 248 |
+
progress=gr.Progress(track_tqdm=True)
|
| 249 |
+
output = cache_pipeline["pipeline"](
|
| 250 |
prompt=prompt,
|
| 251 |
num_frames=16,
|
| 252 |
guidance_scale=1.0,
|
|
|
|
| 266 |
fps=7,
|
| 267 |
)
|
| 268 |
print(f"Saved to {save_path}")
|
| 269 |
+
# pipe_dict[base_model][variant] = pipe_dict[base_model][variant].to("cpu")
|
| 270 |
return save_path, seed
|
| 271 |
|
| 272 |
|
|
|
|
| 277 |
"Aerial uhd 4k view. mid-air flight over fresh and clean mountain river at sunny summer morning. Green trees and sun rays on horizon. Direct on sun.",
|
| 278 |
4
|
| 279 |
],
|
| 280 |
+
["ModelScope T2V", "Anime", "Timelapse misty mountain landscape", 4],
|
| 281 |
[
|
| 282 |
"ModelScope T2V",
|
| 283 |
"WebVid",
|
|
|
|
| 339 |
def update_variant(rs):
|
| 340 |
return gr.update(choices=variants[rs], value=None)
|
| 341 |
|
| 342 |
+
# init_pipelines()
|
| 343 |
|
| 344 |
with gr.Blocks(css=css) as demo:
|
| 345 |
|