Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -18,19 +18,6 @@ bases = {
|
|
18 |
"Anime": "Yntec/mistoonAnime2"
|
19 |
}
|
20 |
|
21 |
-
motion_models = {
|
22 |
-
"Default": None,
|
23 |
-
"Zoom in": "guoyww/animatediff-motion-lora-zoom-in",
|
24 |
-
"Zoom out": "guoyww/animatediff-motion-lora-zoom-out",
|
25 |
-
"Tilt up": "guoyww/animatediff-motion-lora-tilt-up",
|
26 |
-
"Tilt down": "guoyww/animatediff-motion-lora-tilt-down",
|
27 |
-
"Pan left": "guoyww/animatediff-motion-lora-pan-left",
|
28 |
-
"Pan right": "guoyww/animatediff-motion-lora-pan-right",
|
29 |
-
"Roll left": "guoyww/animatediff-motion-lora-rolling-anticlockwise",
|
30 |
-
"Roll right": "guoyww/animatediff-motion-lora-rolling-clockwise",
|
31 |
-
}
|
32 |
-
|
33 |
-
|
34 |
# Preload models
|
35 |
if not torch.cuda.is_available():
|
36 |
raise NotImplementedError("No GPU detected!")
|
@@ -38,31 +25,28 @@ if not torch.cuda.is_available():
|
|
38 |
device = "cuda"
|
39 |
dtype = torch.float16
|
40 |
|
|
|
|
|
41 |
pipes = {}
|
42 |
for base_name, base_path in bases.items():
|
43 |
pipe = AnimateDiffPipeline.from_pretrained(base_path, torch_dtype=dtype).to(device)
|
44 |
pipe.scheduler = EulerDiscreteScheduler.from_config(pipe.scheduler.config, timestep_spacing="trailing", beta_schedule="linear")
|
45 |
pipes[base_name] = pipe
|
46 |
|
47 |
-
# Load motion models
|
48 |
-
for motion_name, motion_path in motion_models.items():
|
49 |
-
if motion_path:
|
50 |
-
motion_model = MotionAdapter.from_pretrained(motion_path, torch_dtype=dtype).to(device)
|
51 |
-
motion_models[motion_name] = motion_model
|
52 |
-
|
53 |
-
|
54 |
# Function
|
55 |
@spaces.GPU(duration=60,queue=False)
|
56 |
def generate_image(prompt, base="Realistic", motion="Default", step=8, progress=gr.Progress()):
|
57 |
global pipes
|
58 |
-
global
|
59 |
|
60 |
pipe = pipes[base]
|
61 |
|
62 |
-
if
|
63 |
-
pipe.
|
64 |
-
|
65 |
-
|
|
|
|
|
66 |
|
67 |
|
68 |
# Load step model if not already loaded
|
|
|
18 |
"Anime": "Yntec/mistoonAnime2"
|
19 |
}
|
20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
# Preload models
|
22 |
if not torch.cuda.is_available():
|
23 |
raise NotImplementedError("No GPU detected!")
|
|
|
25 |
device = "cuda"
|
26 |
dtype = torch.float16
|
27 |
|
28 |
+
motion_loaded = None
|
29 |
+
|
30 |
pipes = {}
|
31 |
for base_name, base_path in bases.items():
|
32 |
pipe = AnimateDiffPipeline.from_pretrained(base_path, torch_dtype=dtype).to(device)
|
33 |
pipe.scheduler = EulerDiscreteScheduler.from_config(pipe.scheduler.config, timestep_spacing="trailing", beta_schedule="linear")
|
34 |
pipes[base_name] = pipe
|
35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
# Function
|
37 |
@spaces.GPU(duration=60,queue=False)
|
38 |
def generate_image(prompt, base="Realistic", motion="Default", step=8, progress=gr.Progress()):
|
39 |
global pipes
|
40 |
+
global motion_loaded
|
41 |
|
42 |
pipe = pipes[base]
|
43 |
|
44 |
+
if motion_loaded != motion:
|
45 |
+
pipe.unload_lora_weights()
|
46 |
+
if motion != "":
|
47 |
+
pipe.load_lora_weights(motion, adapter_name="motion")
|
48 |
+
pipe.set_adapters(["motion"], [0.7])
|
49 |
+
motion_loaded = motion
|
50 |
|
51 |
|
52 |
# Load step model if not already loaded
|