File size: 1,263 Bytes
d79f7f8 5786976 d79f7f8 5786976 d79f7f8 2b9362b d79f7f8 |
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 |
import gradio as gr
import torch
from diffusers import DiffusionPipeline, DPMSolverMultistepScheduler
from diffusers.utils import export_to_video
# Initialize the diffusion pipeline
pipe = DiffusionPipeline.from_pretrained(
"heboya8/text2video-test-2",
torch_dtype=torch.float16,
# variant="fp16",
trust_remote_code=True,
)
# Optimize for GPU memory
pipe.enable_model_cpu_offload()
pipe.enable_vae_slicing()
def generate_video(prompt):
try:
# Generate video frames
video_frames = pipe(
prompt,
num_inference_steps=1,
num_frames=1
).frames
# Export frames to video file
video_path = export_to_video(video_frames, output_video_path="output_video.mp4")
return video_path
except Exception as e:
return f"Error generating video: {str(e)}"
# Create Gradio interface
interface = gr.Interface(
fn=generate_video,
inputs=gr.Textbox(
label="Enter your prompt",
placeholder="e.g., a flower in a garden"
),
outputs=gr.Video(label="Generated Video"),
title="Text-to-Video Generator",
description="Enter a text prompt to generate a video using the diffusion model."
)
# Launch the app
interface.launch() |