Kvikontent commited on
Commit
d18f074
1 Parent(s): a3e5352

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 DiffusionPipeline
3
+ import torch
4
+ from PIL import Image
5
+ import spaces
6
+
7
+ # Load the pre-trained pipeline
8
+ pipeline = DiffusionPipeline.from_pretrained("stabilityai/stable-video-diffusion-img2vid-xt-1-1")
9
+
10
+ # Define the Gradio interface
11
+ interface = gr.Interface(
12
+ fn=lambda img: generate_video(img),
13
+ inputs=gr.Image(type="pil"),
14
+ outputs=gr.Video(),
15
+ title="Stable Video Diffusion",
16
+ description="Upload an image to generate a video",
17
+ theme="soft"
18
+ )
19
+
20
+ # Define the function to generate the video
21
+ def generate_video(img):
22
+ # Convert the input image to a tensor
23
+ img_tensor = torch.tensor(img).unsqueeze(0) / 255.0
24
+
25
+ # Run the pipeline to generate the video
26
+ output = pipeline(img_tensor)
27
+
28
+ # Extract the video frames from the output
29
+ video_frames = output["video_frames"]
30
+
31
+ # Convert the video frames to a video
32
+ video = []
33
+ for frame in video_frames:
34
+ video.append(Image.fromarray(frame.detach().cpu().numpy()))
35
+
36
+ # Return the generated video
37
+ return video
38
+
39
+ # Launch the Gradio app
40
+ interface.launch()