File size: 1,455 Bytes
cf7c71a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gc
import os
import time
import gradio as gr
import imageio
import torch

from skyreels_v2_infer.modules import download_model
# from skyreels_v2_infer.pipelines import Image2VideoPipeline
from skyreels_v2_infer.pipelines import PromptEnhancer
# from skyreels_v2_infer.pipelines import resizecrop
from skyreels_v2_infer.pipelines import Text2VideoPipeline

model_id = "Skywork/SkyReels-V2-T2V-14B-720P"

pipe = Text2VideoPipeline(
    model_path=download_model(model_id),
    dit_path=download_model(model_id),
    use_usp=False,
    offload=True
)


def generate(prompt, use_prompt_enhancer):
    if use_prompt_enhancer:
        enhancer = PromptEnhancer()
        prompt = enhancer(prompt)
        del enhancer
        gc.collect()
        torch.cuda.empty_cache()

    seed = int(time.time()) % 999999
    frames = pipe(
        prompt=prompt,
        negative_prompt="ugly, blurry, low quality",
        num_frames=96,
        num_inference_steps=30,
        guidance_scale=6.0,
        shift=8.0,
        generator=torch.Generator("cuda").manual_seed(seed),
        height=1280,
        width=720
    )[0]

    os.makedirs("videos", exist_ok=True)
    path = f"videos/out_{seed}.mp4"
    imageio.mimsave(path, frames, fps=24)
    return path


app = gr.Interface(
    fn=generate,
    inputs=gr.Textbox(label="Prompt"),
    outputs=gr.Video(label="Generated Video"),
    title="SkyReels V2 T2V"
)


if __name__ == "__main__":
    app.launch()