hanzla commited on
Commit
4ffd894
·
1 Parent(s): ff629ba

adapters added

Browse files
Files changed (1) hide show
  1. app.py +24 -8
app.py CHANGED
@@ -6,6 +6,18 @@ from diffusers.utils import export_to_video
6
  import uuid
7
  import spaces
8
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  device = "cuda"
10
  adapter = MotionAdapter.from_pretrained("guoyww/animatediff-motion-adapter-v1-5-2", torch_dtype=torch.float16)
11
  model_id = "SG161222/Realistic_Vision_V5.1_noVAE"
@@ -26,17 +38,23 @@ scheduler = DDIMScheduler.from_pretrained(
26
  )
27
  pipe.scheduler = scheduler
28
  @spaces.GPU
29
- def generate_video(prompt, guidance_scale, num_inference_steps, num_frames, adapter_choice):
30
  pipe.to(device)
31
 
32
  # Set adapters based on user selection
33
- if adapter_choice:
34
- pipe.set_adapters([adapter_choice], adapter_weights=[1.0])
 
 
 
 
 
 
35
 
36
  output = pipe(
37
  prompt=prompt,
38
  negative_prompt="bad quality, worse quality",
39
- num_frames=num_frames,
40
  guidance_scale=guidance_scale,
41
  num_inference_steps=num_inference_steps,
42
  )
@@ -45,8 +63,7 @@ def generate_video(prompt, guidance_scale, num_inference_steps, num_frames, adap
45
  export_to_video(output.frames[0], path, fps=10)
46
  return path
47
 
48
- # Available adapters (replace with your actual adapter names)
49
- adapter_options = ["zoom-out", "pan-left"]
50
 
51
  iface = gr.Interface(
52
  fn=generate_video,
@@ -54,8 +71,7 @@ iface = gr.Interface(
54
  gr.Textbox(label="Enter your prompt"),
55
  gr.Slider(minimum=0.5, maximum=10, value=7.5, label="Guidance Scale"),
56
  gr.Slider(minimum=4, maximum=24, step=4, value=4, label="Inference Steps"),
57
- gr.Slider(minimum=16, maximum=64, step=1, value=16, label="Frames"),
58
- gr.Dropdown(choices=adapter_options, label="Select Adapter") # Add dropdown for adapter selection
59
  ],
60
  outputs=gr.Video(label="Generated Video"),
61
  )
 
6
  import uuid
7
  import spaces
8
 
9
+ # Available adapters (replace with your actual adapter names)
10
+ adapter_options = {
11
+ "zoom-out":"guoyww/animatediff-motion-lora-zoom-out",
12
+ "zoom-in":"guoyww/animatediff-motion-lora-zoom-in",
13
+ "pan-left":"guoyww/animatediff-motion-lora-pan-left",
14
+ "pan-right":"guoyww/animatediff-motion-lora-pan-right",
15
+ "roll-clockwise":"guoyww/animatediff-motion-lora-rolling-clockwise",
16
+ "roll-anticlockwise":"guoyww/animatediff-motion-lora-rolling-anticlockwise",
17
+ "tilt-up":"guoyww/animatediff-motion-lora-tilt-up",
18
+ "tilt-down":"guoyww/animatediff-motion-lora-tilt-down"
19
+ }
20
+
21
  device = "cuda"
22
  adapter = MotionAdapter.from_pretrained("guoyww/animatediff-motion-adapter-v1-5-2", torch_dtype=torch.float16)
23
  model_id = "SG161222/Realistic_Vision_V5.1_noVAE"
 
38
  )
39
  pipe.scheduler = scheduler
40
  @spaces.GPU
41
+ def generate_video(prompt, guidance_scale, num_inference_steps, adapter_choices):
42
  pipe.to(device)
43
 
44
  # Set adapters based on user selection
45
+ if adapter_choices:
46
+ for i in range(len(adapter_choices)):
47
+ adapter_name = adapter_choices[i]
48
+ pipe.load_lora_weights(
49
+ adapter_options[adapter_name], adapter_name=adapter_name,
50
+ )
51
+ pipe.set_adapters(adapter_choices, adapter_weights=[1.0] * len(adapter_choices))
52
+ print(adapter_choices)
53
 
54
  output = pipe(
55
  prompt=prompt,
56
  negative_prompt="bad quality, worse quality",
57
+ num_frames=16,
58
  guidance_scale=guidance_scale,
59
  num_inference_steps=num_inference_steps,
60
  )
 
63
  export_to_video(output.frames[0], path, fps=10)
64
  return path
65
 
66
+
 
67
 
68
  iface = gr.Interface(
69
  fn=generate_video,
 
71
  gr.Textbox(label="Enter your prompt"),
72
  gr.Slider(minimum=0.5, maximum=10, value=7.5, label="Guidance Scale"),
73
  gr.Slider(minimum=4, maximum=24, step=4, value=4, label="Inference Steps"),
74
+ gr.Dropdown(choices=adapter_options.keys(), label="Select Adapter(s)", type="checkbox") # Updated for multiple selections
 
75
  ],
76
  outputs=gr.Video(label="Generated Video"),
77
  )