Sabbirr12 commited on
Commit
72090d7
Β·
verified Β·
1 Parent(s): 33d5826

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -0
app.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 # Gradio will auto-render as video
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()