pgonzzz commited on
Commit
22e85ae
·
verified ·
1 Parent(s): 86a078e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -21
app.py CHANGED
@@ -1,26 +1,59 @@
1
  import gradio as gr
2
- import subprocess
3
  import os
4
- import random
5
  import time
 
 
 
 
6
 
7
- def generate(prompt):
8
- seed = random.randint(0, 999999)
9
- command = f"python generate_video.py --prompt \"{prompt}\" --resolution 540P --fps 24 --outdir=outputs --seed {seed}"
10
- os.makedirs("outputs", exist_ok=True)
11
- subprocess.run(command, shell=True)
12
-
13
- # Buscar el último vídeo generado
14
- files = sorted(os.listdir("result/outputs"), key=lambda x: os.path.getmtime(os.path.join("result/outputs", x)))
15
- if files:
16
- video_path = os.path.join("result/outputs", files[-1])
17
- return video_path
18
- else:
19
- return "No video generated"
20
-
21
- iface = gr.Interface(fn=generate,
22
- inputs=gr.Textbox(label="Prompt para generar video"),
23
- outputs=gr.Video(label="Video generado"))
24
-
25
- iface.launch()
26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ import torch
3
  import os
 
4
  import time
5
+ import imageio
6
+ from diffusers.utils import load_image
7
+ from skyreels_v2_infer.modules import download_model
8
+ from skyreels_v2_infer.pipelines import Text2VideoPipeline
9
 
10
+ def generate_video(prompt):
11
+ model_id = "Skywork/SkyReels-V2-T2V-14B-540P"
12
+ model_path = download_model(model_id)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
 
14
+ pipe = Text2VideoPipeline(
15
+ model_path=model_path,
16
+ dit_path=model_path,
17
+ use_usp=False,
18
+ offload=True,
19
+ )
20
+
21
+ height = 544
22
+ width = 960
23
+ seed = int(time.time())
24
+ generator = torch.Generator(device="cuda").manual_seed(seed)
25
+
26
+ kwargs = {
27
+ "prompt": prompt,
28
+ "negative_prompt": "static, blurred, low quality",
29
+ "num_frames": 97,
30
+ "num_inference_steps": 30,
31
+ "guidance_scale": 6.0,
32
+ "shift": 8.0,
33
+ "generator": generator,
34
+ "height": height,
35
+ "width": width,
36
+ }
37
+
38
+ with torch.cuda.amp.autocast(dtype=pipe.transformer.dtype), torch.no_grad():
39
+ video_frames = pipe(**kwargs)[0]
40
+
41
+ timestamp = time.strftime("%Y%m%d_%H%M%S")
42
+ filename = f"output_{timestamp}.mp4"
43
+ os.makedirs("video_out", exist_ok=True)
44
+ path = os.path.join("video_out", filename)
45
+ imageio.mimwrite(path, video_frames, fps=24, quality=8)
46
+ return path
47
+
48
+ with gr.Blocks() as demo:
49
+ gr.Markdown("# SkyReels V2")
50
+ with gr.Row():
51
+ prompt_input = gr.Textbox(label="Prompt para generar video", placeholder="Describe la escena que quieres ver")
52
+ with gr.Row():
53
+ run_button = gr.Button("Generar video")
54
+ with gr.Row():
55
+ output_video = gr.Video(label="Video generado")
56
+
57
+ run_button.click(fn=generate_video, inputs=prompt_input, outputs=output_video)
58
+
59
+ demo.launch()