YAML Metadata Warning:empty or missing yaml metadata in repo card
Check out the documentation for more information.
import gradio as gr from diffusers import DiffusionPipeline import torch from moviepy.editor import ImageSequenceClip import os
Load the model once at startup
print("Loading the text-to-video model...") model_id = "damo-vilab/text-to-video-ms-1.7b" pipe = DiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16) if torch.cuda.is_available(): pipe = pipe.to("cuda") print("Model loaded successfully!")
Function to generate video
def generate_video(prompt): print(f"Generating video for prompt: {prompt}") try: video_output = pipe(prompt, num_inference_steps=50, height=256, width=256, num_frames=16) video_frames = video_output.frames[0] video_path = "output.mp4" clip = ImageSequenceClip(video_frames, fps=24) clip.write_videofile(video_path, codec="libx264", audio=False) return video_path except Exception as e: return f"Error: {str(e)}"
Gradio interface
interface = gr.Interface( fn=generate_video, inputs=gr.Textbox(label="Enter your text prompt", placeholder="e.g., A bird flying over a lake"), outputs=gr.Video(label="Generated Video"), title="Text-to-Video Generator", description="Enter a text prompt to generate a short video using a free Hugging Face model." )
Launch the app
interface.launch()