fffiloni commited on
Commit
013d033
·
1 Parent(s): a2c642e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -2
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import gradio as gr
2
  import numpy as np
3
  from PIL import Image
 
4
  from moviepy.editor import VideoFileClip
5
  from share_btn import community_icon_html, loading_icon_html, share_js
6
  import torch
@@ -13,11 +14,39 @@ pipe_xl.scheduler = DPMSolverMultistepScheduler.from_config(pipe_xl.scheduler.co
13
  pipe_xl.enable_model_cpu_offload()
14
  pipe_xl.to("cuda")
15
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
  def infer(prompt, video_in):
18
 
19
-
20
- video_frames = pipe_xl(prompt, video=video_in, strength=0.6).frames
21
  video_path = export_to_video(video_frames, output_video_path="xl_result.mp4")
22
 
23
  return "xl_result.mp4", gr.Group.update(visible=True)
 
1
  import gradio as gr
2
  import numpy as np
3
  from PIL import Image
4
+ import cv2
5
  from moviepy.editor import VideoFileClip
6
  from share_btn import community_icon_html, loading_icon_html, share_js
7
  import torch
 
14
  pipe_xl.enable_model_cpu_offload()
15
  pipe_xl.to("cuda")
16
 
17
+ def convert_mp4_to_frames(video_path):
18
+ # Read the video file
19
+ video = cv2.VideoCapture(video_path)
20
+
21
+ frames = []
22
+
23
+ # Iterate through each frame
24
+ while True:
25
+ # Read a frame
26
+ ret, frame = video.read()
27
+
28
+ # If the frame was not successfully read, then we have reached the end of the video
29
+ if not ret:
30
+ break
31
+
32
+ # Convert the frame to grayscale if needed
33
+ # frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
34
+
35
+ # Append the frame to the list of frames
36
+ frames.append(frame)
37
+
38
+ # Release the video object
39
+ video.release()
40
+
41
+ # Convert the list of frames to a numpy array
42
+ frames = np.array(frames)
43
+
44
+ return frames
45
 
46
  def infer(prompt, video_in):
47
 
48
+ video = convert_mp4_to_frames(video_in)
49
+ video_frames = pipe_xl(prompt, video=video, strength=0.6).frames
50
  video_path = export_to_video(video_frames, output_video_path="xl_result.mp4")
51
 
52
  return "xl_result.mp4", gr.Group.update(visible=True)