CoolFace
Apppublic

mrcuddle/I2VGenXL-Text-Image-To-Video

sourceHugging Faceupdated 2y agoView on Hugging Face
27likes
app.py52 linesDownload Raw Back to root
1import gradio as gr2import torch3from diffusers import I2VGenXLPipeline4from diffusers.utils import export_to_gif, load_image5import spaces6 7# Initialize the pipeline8pipeline = I2VGenXLPipeline.from_pretrained("ali-vilab/i2vgen-xl", torch_dtype=torch.float16, variant="fp16")9pipeline.enable_model_cpu_offload()10 11@spaces.GPU(duration=240)12def generate_gif(image, prompt, negative_prompt, num_inference_steps, guidance_scale, seed):13    # Load the image14    image = load_image(image).convert("RGB")15 16    # Set the generator seed17    generator = torch.manual_seed(seed)18 19    # Generate the frames20    frames = pipeline(21        prompt=prompt,22        image=image,23        num_inference_steps=num_inference_steps,24        negative_prompt=negative_prompt,25        guidance_scale=guidance_scale,26        generator=generator27    ).frames[0]28 29    # Export to GIF30    gif_path = "i2v.gif"31    export_to_gif(frames, gif_path)32 33    return gif_path34 35# Create the Gradio interface36iface = gr.Interface(37    fn=generate_gif,38    inputs=[39        gr.Image(type="filepath", label="Input Image"),40        gr.Textbox(lines=2, placeholder="Enter your prompt here...", label="Prompt"),41        gr.Textbox(lines=2, placeholder="Enter your negative prompt here...", label="Negative Prompt"),42        gr.Slider(1, 100, step=1, value=50, label="Number of Inference Steps"),43        gr.Slider(1, 20, step=0.1, value=9.0, label="Guidance Scale"),44        gr.Number(label="Seed", value=8888)45    ],46    outputs=gr.Video(label="Generated GIF"),47    title="I2VGen-XL GIF Generator",48    description="Generate a GIF from an image and a prompt using the I2VGen-XL model."49)50 51# Launch the interface52iface.launch()