File size: 2,523 Bytes
64d8b45
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
64
65
66
import gradio as gr
import torch
from diffusers import LTXVideoPipeline
from huggingface_hub import login
import os

# Memuat pipeline LTX-Video dasar dari Hugging Face
# Model LTX-Video membutuhkan tipe data bfloat16 untuk efisiensi VRAM
pipe = LTXVideoPipeline.from_pretrained(
    "Lightricks/LTX-Video", 
    torch_dtype=torch.bfloat16
)

# Memuat bobot LoRA Black Magic milik FuzzPuppy ke dalam pipeline
pipe.load_lora_weights(
    "FuzzPuppy/LTX-2.3-Black-Magic-LoRA", 
    weight_name="pytorch_lora_weights.safetensors", 
    adapter_name="black_magic"
)
pipe.to("cuda")

def generate_video(prompt, negative_prompt, num_frames, fps, guidance_scale):
    # Mengonfigurasi parameter teks dan menjalankan inferensi
    video_frames = pipe(
        prompt=prompt,
        negative_prompt=negative_prompt,
        num_inference_steps=30,
        num_frames=int(num_frames),
        guidance_scale=float(guidance_scale),
        generator=torch.manual_seed(-1)
    ).frames[0]
    
    # Menyimpan frame video sementara ke format MP4
    output_path = "output_generated.mp4"
    # Catatan: Diffusers LTXVideo memproses penyimpanan video internal atau menggunakan manual export
    # Di bawah ini adalah contoh logika penyimpanan bawaan diffusers untuk video
    from diffusers.utils import export_to_video
    export_to_video(video_frames, output_path, fps=int(fps))
    
    return output_path

# Membuat Antarmuka Grafis Menggunakan Gradio
with gr.Blocks() as demo:
    gr.Markdown("# LTX-2.3 Black Magic LoRA Demo")
    gr.Markdown("Buat video cinematic magis menggunakan model dasar LTX-Video yang dipadukan dengan LoRA Black Magic.")
    
    with gr.Row():
        with gr.Column():
            prompt = gr.Textbox(label="Prompt", placeholder="A wizard casting a dark magic spell, cinematic lighting, 4k...")
            negative_prompt = gr.Textbox(label="Negative Prompt", value="low quality, blurry, distorted")
            frames = gr.Slider(minimum=16, maximum=64, step=8, value=32, label="Jumlah Frame (Durasi)")
            fps = gr.Slider(minimum=8, maximum=24, step=2, value=16, label="FPS")
            guidance = gr.Slider(minimum=1.0, maximum=10.0, step=0.5, value=5.0, label="Guidance Scale")
            btn = gr.Button("Generate Video")
        
        with gr.Column():
            output_video = gr.Video(label="Hasil Video")
            
    btn.click(
        fn=generate_video, 
        inputs=[prompt, negative_prompt, frames, fps, guidance], 
        outputs=output_video
    )

demo.launch()