Kvikontent commited on
Commit
fe3f0e0
1 Parent(s): 5b99609

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +53 -4
app.py CHANGED
@@ -1,7 +1,56 @@
1
  import gradio as gr
 
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
 
5
 
6
- demo = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ import moviepy.editor as mp
3
+ from diffusers import DiffusionPipeline
4
 
5
+ # Load diffusion pipelines
6
+ image_pipeline = DiffusionPipeline.from_pretrained("ByteDance/SDXL-Lightning")
7
+ video_pipeline = DiffusionPipeline.from_pretrained("stabilityai/stable-video-diffusion-img2vid-xt-1-1")
8
 
9
+ @spaces.GPU(duration=120)
10
+ def generate_images(prompt, num_images):
11
+ """Generates images using the image pipeline."""
12
+ images = []
13
+ for _ in range(num_images):
14
+ generated_image = image_pipeline.pipe(prompt=prompt).images[0]
15
+ images.append(generated_image)
16
+ return images
17
+
18
+ @spaces.GPU(duration=120)
19
+ def generate_videos(images):
20
+ """Generates videos from a list of images using the video pipeline."""
21
+ videos = []
22
+ for image in images:
23
+ generated_video = video_pipeline.pipe(images=image).images[0]
24
+ videos.append(generated_video)
25
+ return videos
26
+
27
+ def combine_videos(video_clips):
28
+ """Combines video clips into a single video using moviepy."""
29
+ final_clip = mp.concatenate_videoclips(video_clips)
30
+ return final_clip
31
+
32
+ def generate(prompt, num_images):
33
+ """Generates and combines images and videos."""
34
+ images = generate_images(prompt, num_images)
35
+ video_clips = generate_videos(images)
36
+ combined_video = combine_videos(video_clips)
37
+ return combined_video
38
+
39
+ # Gradio interface with improved formatting and video output
40
+ interface = gr.Interface(
41
+ fn=generate,
42
+ inputs="text",
43
+ outputs="video",
44
+ interpretation="markdown",
45
+ title="AI Video Generation",
46
+ description="Enter a prompt to generate a video using diffusion models.",
47
+ css="""
48
+ .output-video {
49
+ width: 100%; /* Adjust width as needed */
50
+ height: 400px; /* Adjust height as desired */
51
+ }
52
+ """,
53
+ )
54
+
55
+ # Launch the interface
56
+ interface.launch()