Spaces:
Running
on
Zero
Running
on
Zero
guardiancc
commited on
Commit
•
897f5fa
1
Parent(s):
3435d9b
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import spaces
|
2 |
+
import torch
|
3 |
+
from diffusers import CogVideoXImageToVideoPipeline
|
4 |
+
from diffusers.utils import export_to_video, load_image
|
5 |
+
import gradio as gr
|
6 |
+
|
7 |
+
@spaces.GPU(duration=250)
|
8 |
+
def generate_video(prompt, image):
|
9 |
+
# Carregar a pipeline pré-treinada
|
10 |
+
pipe = CogVideoXImageToVideoPipeline.from_pretrained(
|
11 |
+
"THUDM/CogVideoX-5b-I2V",
|
12 |
+
torch_dtype=torch.bfloat16
|
13 |
+
)
|
14 |
+
|
15 |
+
pipe.enable_sequential_cpu_offload()
|
16 |
+
pipe.vae.enable_tiling()
|
17 |
+
pipe.vae.enable_slicing()
|
18 |
+
|
19 |
+
video = pipe(
|
20 |
+
prompt=prompt,
|
21 |
+
image=image,
|
22 |
+
num_videos_per_prompt=1,
|
23 |
+
num_inference_steps=50,
|
24 |
+
num_frames=49,
|
25 |
+
guidance_scale=6,
|
26 |
+
generator=torch.Generator(device="cuda").manual_seed(42),
|
27 |
+
).frames[0]
|
28 |
+
|
29 |
+
video_path = "output.mp4"
|
30 |
+
export_to_video(video, video_path, fps=8)
|
31 |
+
|
32 |
+
return video_path
|
33 |
+
|
34 |
+
# Interface Gradio
|
35 |
+
with gr.Blocks() as demo:
|
36 |
+
gr.Markdown("# Image to Video Generation")
|
37 |
+
|
38 |
+
with gr.Row():
|
39 |
+
# Entrada de texto para o prompt
|
40 |
+
prompt_input = gr.Textbox(label="Prompt", value="A little girl is riding a bicycle at high speed. Focused, detailed, realistic.")
|
41 |
+
|
42 |
+
# Upload de imagem
|
43 |
+
image_input = gr.Image(label="Upload an Image", type="pil")
|
44 |
+
|
45 |
+
# Botão para gerar o vídeo
|
46 |
+
generate_button = gr.Button("Generate Video")
|
47 |
+
|
48 |
+
# Saída do vídeo gerado
|
49 |
+
video_output = gr.Video(label="Generated Video")
|
50 |
+
|
51 |
+
# Ação ao clicar no botão
|
52 |
+
generate_button.click(fn=generate_video, inputs=[prompt_input, image_input], outputs=video_output)
|
53 |
+
|
54 |
+
# Rodar a interface
|
55 |
+
demo.launch()
|