Spaces:
Running
Running
File size: 1,956 Bytes
0915e96 505f557 9b36fc9 0915e96 505f557 0915e96 505f557 0915e96 505f557 0915e96 505f557 9b36fc9 0915e96 9b36fc9 0915e96 505f557 9b36fc9 505f557 9b36fc9 505f557 0915e96 9b36fc9 0915e96 9b36fc9 505f557 9b36fc9 505f557 9b36fc9 505f557 9b36fc9 505f557 9b36fc9 505f557 9b36fc9 0915e96 |
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 47 48 49 50 51 52 53 |
import gradio as gr
import torch
from diffusers import StableDiffusionPipeline, DiffusionPipeline
import os
# Load Text-to-Image Model (Redshift Diffusion)
device = "cuda" if torch.cuda.is_available() else "cpu"
image_pipe = StableDiffusionPipeline.from_pretrained(
"nitrosocke/redshift-diffusion", torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32
).to(device)
# Load Image-to-Video Model (Zeroscope v2 XL)
video_model = DiffusionPipeline.from_pretrained(
"cerspense/zeroscope_v2_XL", torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32
).to(device)
# Function to Generate Image from Text
def generate_image(prompt):
image = image_pipe(prompt).images[0]
image_path = "generated_image.png"
image.save(image_path)
return image_path
# Function to Convert Image to Video
def generate_video(image_path):
image = image_pipe(prompt).images[0] # Reload image for video generation
video_frames = video_model(image) # Generate video frames
video_path = "generated_video.mp4"
video_frames.save(video_path) # Save output video
return video_path
# Gradio Interface
with gr.Blocks() as demo:
gr.Markdown("## 🎨 AI Cartoon Image & Video Generator")
with gr.Row():
prompt_input = gr.Textbox(label="Enter Text Prompt", placeholder="A 3D cartoon cat playing in a park")
generate_image_btn = gr.Button("Generate Image")
image_output = gr.Image(label="Generated Image")
with gr.Row():
generate_video_btn = gr.Button("Convert to Video")
video_output = gr.Video(label="Generated Video")
download_image = gr.File(label="Download Image")
download_video = gr.File(label="Download Video")
generate_image_btn.click(generate_image, inputs=[prompt_input], outputs=[image_output, download_image])
generate_video_btn.click(generate_video, inputs=[image_output], outputs=[video_output, download_video])
demo.launch()
|