File size: 2,202 Bytes
5bd9da0
 
 
 
 
 
 
 
 
 
 
 
30787d4
ff629ba
30787d4
 
ff629ba
30787d4
5bd9da0
 
 
 
 
 
 
 
 
 
30787d4
5bd9da0
30787d4
 
 
 
 
5bd9da0
 
 
f9a5dfd
c19b47e
 
5bd9da0
 
 
 
 
 
30787d4
 
 
5bd9da0
c19b47e
 
 
 
 
30787d4
 
c19b47e
5bd9da0
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import gradio as gr
import torch
from diffusers import AnimateDiffPipeline, DDIMScheduler, MotionAdapter
from diffusers.utils import export_to_gif
from diffusers.utils import export_to_video
import uuid
import spaces

device = "cuda"
adapter = MotionAdapter.from_pretrained("guoyww/animatediff-motion-adapter-v1-5-2", torch_dtype=torch.float16)
model_id = "SG161222/Realistic_Vision_V5.1_noVAE"
pipe = AnimateDiffPipeline.from_pretrained(model_id, motion_adapter=adapter, torch_dtype=torch.float16).to(device)
pipe.load_lora_weights(
    "guoyww/animatediff-motion-lora-zoom-out", adapter_name="zoom-out",
)
pipe.load_lora_weights(
    "guoyww/animatediff-motion-lora-zoom-out", adapter_name="pan-left",
)
scheduler = DDIMScheduler.from_pretrained(
        model_id,
        subfolder="scheduler",
        clip_sample=False,
        timestep_spacing="linspace",
        beta_schedule="linear",
        steps_offset=1,
)
pipe.scheduler = scheduler
@spaces.GPU
def generate_video(prompt, guidance_scale, num_inference_steps, num_frames, adapter_choice):
    pipe.to(device)

    # Set adapters based on user selection
    if adapter_choice:
        pipe.set_adapters([adapter_choice], adapter_weights=[1.0])

    output = pipe(
        prompt=prompt,
        negative_prompt="bad quality, worse quality",
        num_frames=num_frames,
        guidance_scale=guidance_scale,
        num_inference_steps=num_inference_steps,
    )
    name = str(uuid.uuid4()).replace("-", "")
    path = f"/tmp/{name}.mp4"
    export_to_video(output.frames[0], path, fps=10)
    return path

# Available adapters (replace with your actual adapter names)
adapter_options = ["zoom-out", "pan-left"]

iface = gr.Interface(
    fn=generate_video,
    inputs=[
        gr.Textbox(label="Enter your prompt"),
        gr.Slider(minimum=0.5, maximum=10, value=7.5, label="Guidance Scale"),
        gr.Slider(minimum=4, maximum=24, step=4, value=4, label="Inference Steps"),
        gr.Slider(minimum=16, maximum=64, step=1, value=16, label="Frames"),
        gr.Dropdown(choices=adapter_options, label="Select Adapter")  # Add dropdown for adapter selection
    ],
    outputs=gr.Video(label="Generated Video"),
)

iface.launch()