Spaces:
Runtime error
Runtime error
1littlecoder
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -4,14 +4,12 @@ from moviepy.editor import AudioFileClip, ImageClip, CompositeVideoClip
|
|
4 |
import tempfile
|
5 |
import os
|
6 |
|
7 |
-
def create_waveform_video(image,
|
8 |
-
# Save uploaded
|
9 |
image_path = tempfile.mktemp(suffix=".png")
|
10 |
-
audio_path = tempfile.mktemp(suffix=".mp3")
|
11 |
video_path = tempfile.mktemp(suffix=".mp4")
|
12 |
|
13 |
image.save(image_path)
|
14 |
-
audio.save(audio_path)
|
15 |
|
16 |
# Load audio
|
17 |
audio_clip = AudioFileClip(audio_path)
|
@@ -27,17 +25,12 @@ def create_waveform_video(image, audio):
|
|
27 |
# Normalize waveform for overlay
|
28 |
waveform = np.interp(waveform, (waveform.min(), waveform.max()), (-1, 1))
|
29 |
|
30 |
-
# Overlay waveform on image (optional customization: size and position of waveform)
|
31 |
-
waveform_clip = ImageClip(image_path).set_duration(audio_clip.duration)
|
32 |
-
waveform_clip = waveform_clip.fx(CompositeVideoClip, [[waveform, 'center', 0.8]])
|
33 |
-
|
34 |
# Combine image and audio into one video
|
35 |
-
final_clip =
|
36 |
final_clip.write_videofile(video_path, codec="libx264", fps=24)
|
37 |
|
38 |
# Cleanup temporary files
|
39 |
os.remove(image_path)
|
40 |
-
os.remove(audio_path)
|
41 |
|
42 |
return video_path
|
43 |
|
@@ -45,7 +38,7 @@ iface = gr.Interface(
|
|
45 |
fn=create_waveform_video,
|
46 |
inputs=[
|
47 |
gr.Image(type="pil", label="Upload Image"),
|
48 |
-
gr.Audio(type="
|
49 |
],
|
50 |
outputs=gr.Video(label="Generated Video"),
|
51 |
title="Image + Audio to Video with Waveform Overlay"
|
|
|
4 |
import tempfile
|
5 |
import os
|
6 |
|
7 |
+
def create_waveform_video(image, audio_path):
|
8 |
+
# Save uploaded image temporarily
|
9 |
image_path = tempfile.mktemp(suffix=".png")
|
|
|
10 |
video_path = tempfile.mktemp(suffix=".mp4")
|
11 |
|
12 |
image.save(image_path)
|
|
|
13 |
|
14 |
# Load audio
|
15 |
audio_clip = AudioFileClip(audio_path)
|
|
|
25 |
# Normalize waveform for overlay
|
26 |
waveform = np.interp(waveform, (waveform.min(), waveform.max()), (-1, 1))
|
27 |
|
|
|
|
|
|
|
|
|
28 |
# Combine image and audio into one video
|
29 |
+
final_clip = img_clip.set_audio(audio_clip)
|
30 |
final_clip.write_videofile(video_path, codec="libx264", fps=24)
|
31 |
|
32 |
# Cleanup temporary files
|
33 |
os.remove(image_path)
|
|
|
34 |
|
35 |
return video_path
|
36 |
|
|
|
38 |
fn=create_waveform_video,
|
39 |
inputs=[
|
40 |
gr.Image(type="pil", label="Upload Image"),
|
41 |
+
gr.Audio(type="filepath", label="Upload Audio")
|
42 |
],
|
43 |
outputs=gr.Video(label="Generated Video"),
|
44 |
title="Image + Audio to Video with Waveform Overlay"
|