Spaces:
Runtime error
Runtime error
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() | |