Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -9,6 +9,12 @@ from diffusers.utils import export_to_video
|
|
9 |
from huggingface_hub import hf_hub_download
|
10 |
from safetensors.torch import load_file
|
11 |
from PIL import Image
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
# Constants
|
14 |
bases = {
|
@@ -77,8 +83,44 @@ def generate_image(prompt, base, motion, step, progress=gr.Progress()):
|
|
77 |
return None
|
78 |
|
79 |
name = str(uuid.uuid4()).replace("-", "")
|
80 |
-
|
81 |
export_to_video(output.frames[0], path, fps=10)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
82 |
return path
|
83 |
|
84 |
|
|
|
9 |
from huggingface_hub import hf_hub_download
|
10 |
from safetensors.torch import load_file
|
11 |
from PIL import Image
|
12 |
+
from gradio_client import Client, file
|
13 |
+
from moviepy.editor import VideoFileClip, AudioFileClip, concatenate_videoclips
|
14 |
+
|
15 |
+
|
16 |
+
# using tango2 via Gradio python client
|
17 |
+
client = Client("declare-lab/tango2")
|
18 |
|
19 |
# Constants
|
20 |
bases = {
|
|
|
83 |
return None
|
84 |
|
85 |
name = str(uuid.uuid4()).replace("-", "")
|
86 |
+
video_path = f"/tmp/{name}.mp4"
|
87 |
export_to_video(output.frames[0], path, fps=10)
|
88 |
+
|
89 |
+
audio_path = tango2(prompt)
|
90 |
+
final_video_path = fuse_together(audio_path, video_path)
|
91 |
+
|
92 |
+
return final_video_path
|
93 |
+
|
94 |
+
|
95 |
+
def tango2(prompt):
|
96 |
+
results = client.predict(
|
97 |
+
prompt=prompt,
|
98 |
+
steps=100,
|
99 |
+
guidance=3,
|
100 |
+
api_name="/predict"
|
101 |
+
)
|
102 |
+
return results
|
103 |
+
|
104 |
+
def fuse_together(audio, video):
|
105 |
+
|
106 |
+
# Load your video and audio files
|
107 |
+
video_clip = VideoFileClip(video)
|
108 |
+
audio_clip = AudioFileClip(audio)
|
109 |
+
|
110 |
+
# Loop the video twice
|
111 |
+
looped_video = concatenate_videoclips([video_clip, video_clip])
|
112 |
+
|
113 |
+
# Cut the audio to match the duration of the looped video
|
114 |
+
looped_audio = audio_clip.subclip(0, looped_video.duration)
|
115 |
+
|
116 |
+
# Set the audio of the looped video to the adjusted audio clip
|
117 |
+
final_video = looped_video.set_audio(looped_audio)
|
118 |
+
|
119 |
+
# Write the result to a file (output will be twice the length of the original video)
|
120 |
+
name = str(uuid.uuid4()).replace("-", "")
|
121 |
+
path = f"/tmp/{name}.mp4"
|
122 |
+
final_video.write_videofile(path, codec="libx264", audio_codec="aac")
|
123 |
+
|
124 |
return path
|
125 |
|
126 |
|