|
|
import gradio as gr |
|
|
from diffusers import StableDiffusionPipeline, DiffusionPipeline |
|
|
import torch, imageio |
|
|
|
|
|
|
|
|
img_model = "runwayml/stable-diffusion-v1-5" |
|
|
img_pipe = StableDiffusionPipeline.from_pretrained(img_model, torch_dtype=torch.float32) |
|
|
img_pipe = img_pipe.to("cpu") |
|
|
|
|
|
|
|
|
vid_model = "damo-vilab/text-to-video-ms-1.7b" |
|
|
vid_pipe = DiffusionPipeline.from_pretrained(vid_model, torch_dtype=torch.float32) |
|
|
vid_pipe = vid_pipe.to("cpu") |
|
|
|
|
|
|
|
|
def generate_image(prompt): |
|
|
image = img_pipe(prompt).images[0] |
|
|
return image |
|
|
|
|
|
|
|
|
def generate_video(prompt): |
|
|
video_frames = vid_pipe(prompt, num_frames=8).frames |
|
|
output_path = "output.mp4" |
|
|
imageio.mimsave(output_path, video_frames, fps=8) |
|
|
return output_path |
|
|
|
|
|
|
|
|
with gr.Blocks() as demo: |
|
|
gr.Markdown("## 🎨 Free AI Image + Video Generator") |
|
|
with gr.Tab("🖼️ Image Generator"): |
|
|
text_in = gr.Textbox(label="ছবির জন্য প্রম্পট লিখুন") |
|
|
img_out = gr.Image(type="pil") |
|
|
btn1 = gr.Button("Generate Image") |
|
|
btn1.click(generate_image, inputs=text_in, outputs=img_out) |
|
|
|
|
|
with gr.Tab("🎬 Video Generator"): |
|
|
text_in2 = gr.Textbox(label="ভিডিওর জন্য প্রম্পট লিখুন") |
|
|
vid_out = gr.Video() |
|
|
btn2 = gr.Button("Generate Video") |
|
|
btn2.click(generate_video, inputs=text_in2, outputs=vid_out) |
|
|
|
|
|
demo.launch() |