Update app.py
Browse files
app.py
CHANGED
|
@@ -1,42 +1,40 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from diffusers import StableDiffusionPipeline, DiffusionPipeline
|
| 3 |
-
import torch
|
|
|
|
| 4 |
|
| 5 |
-
# Load Image
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
|
| 10 |
-
# Load Video
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
|
| 15 |
-
# Image generation function
|
| 16 |
def generate_image(prompt):
|
| 17 |
-
image =
|
| 18 |
return image
|
| 19 |
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
video_frames
|
| 23 |
-
output_path = "output.mp4"
|
| 24 |
-
imageio.mimsave(output_path, video_frames, fps=8)
|
| 25 |
-
return output_path
|
| 26 |
|
| 27 |
-
# Gradio Tabs UI
|
| 28 |
with gr.Blocks() as demo:
|
| 29 |
-
gr.Markdown("## 🎨
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
with gr.
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
|
|
|
|
|
|
| 41 |
|
| 42 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from diffusers import StableDiffusionPipeline, DiffusionPipeline
|
| 3 |
+
import torch
|
| 4 |
+
from PIL import Image
|
| 5 |
|
| 6 |
+
# Load Text ➤ Image model
|
| 7 |
+
text2img = StableDiffusionPipeline.from_pretrained(
|
| 8 |
+
"runwayml/stable-diffusion-v1-5", torch_dtype=torch.float16
|
| 9 |
+
).to("cuda")
|
| 10 |
|
| 11 |
+
# Load Image ➤ Video model
|
| 12 |
+
img2vid = DiffusionPipeline.from_pretrained(
|
| 13 |
+
"damo-vilab/image-to-video", torch_dtype=torch.float16, variant="fp16"
|
| 14 |
+
).to("cuda")
|
| 15 |
|
|
|
|
| 16 |
def generate_image(prompt):
|
| 17 |
+
image = text2img(prompt).images[0]
|
| 18 |
return image
|
| 19 |
|
| 20 |
+
def generate_video(image):
|
| 21 |
+
video_frames = img2vid(image).frames
|
| 22 |
+
return video_frames
|
|
|
|
|
|
|
|
|
|
| 23 |
|
|
|
|
| 24 |
with gr.Blocks() as demo:
|
| 25 |
+
gr.Markdown("## 🎨 Text ➤ Image ➤ Video Generator")
|
| 26 |
+
|
| 27 |
+
with gr.Row():
|
| 28 |
+
prompt = gr.Textbox(label="📝 Enter Prompt")
|
| 29 |
+
img_output = gr.Image(label="🖼️ Generated Image")
|
| 30 |
+
btn_img = gr.Button("Generate Image")
|
| 31 |
+
|
| 32 |
+
with gr.Row():
|
| 33 |
+
img_input = gr.Image(label="📥 Drop Image Here")
|
| 34 |
+
vid_output = gr.Video(label="🎬 Generated Video")
|
| 35 |
+
btn_vid = gr.Button("Generate Video")
|
| 36 |
+
|
| 37 |
+
btn_img.click(fn=generate_image, inputs=prompt, outputs=img_output)
|
| 38 |
+
btn_vid.click(fn=generate_video, inputs=img_input, outputs=vid_output)
|
| 39 |
|
| 40 |
demo.launch()
|