Spaces:
Build error
Build error
j
commited on
Commit
·
cc9ce25
1
Parent(s):
e9be68c
convert video inputs and remove HARP stuff
Browse files
app.py
CHANGED
|
@@ -4,10 +4,17 @@ from audioldm import build_model, text_to_audio
|
|
| 4 |
import gradio as gr
|
| 5 |
import soundfile as sf
|
| 6 |
from datetime import datetime
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
audioldm = build_model(model_name="audioldm-l-full")
|
| 9 |
|
| 10 |
def process_fn(input_audio_path, seed, guidance_scale, num_inference_steps, num_candidates, audio_length_in_s):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
waveform = text_to_audio(
|
| 12 |
audioldm,
|
| 13 |
'placeholder',
|
|
@@ -26,14 +33,17 @@ def process_fn(input_audio_path, seed, guidance_scale, num_inference_steps, num_
|
|
| 26 |
return filename
|
| 27 |
|
| 28 |
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
|
|
|
|
|
|
| 35 |
|
| 36 |
-
|
|
|
|
| 37 |
# Define your Gradio interface
|
| 38 |
inputs = [
|
| 39 |
gr.Audio(
|
|
@@ -66,13 +76,11 @@ with gr.Blocks() as webapp:
|
|
| 66 |
minimum=2.5, maximum=10.0,
|
| 67 |
step=2.5, value=5,
|
| 68 |
label="Duration"
|
| 69 |
-
)
|
| 70 |
-
]
|
| 71 |
|
| 72 |
output = gr.Audio(label="Audio Output", type="filepath", format="wav", elem_id="audio")
|
|
|
|
| 73 |
|
| 74 |
-
ctrls_data, ctrls_button, process_button, cancel_button = build_endpoint(inputs, output, process_fn, card)
|
| 75 |
-
|
| 76 |
-
# queue the webapp: https://www.gradio.app/guides/setting-up-a-demo-for-maximum-performance
|
| 77 |
webapp.queue()
|
| 78 |
webapp.launch()
|
|
|
|
| 4 |
import gradio as gr
|
| 5 |
import soundfile as sf
|
| 6 |
from datetime import datetime
|
| 7 |
+
import subprocess
|
| 8 |
+
import os
|
| 9 |
+
import sys
|
| 10 |
|
| 11 |
audioldm = build_model(model_name="audioldm-l-full")
|
| 12 |
|
| 13 |
def process_fn(input_audio_path, seed, guidance_scale, num_inference_steps, num_candidates, audio_length_in_s):
|
| 14 |
+
video_extensions = (".mp4", ".avi", ".mkv", ".flv", ".mov", ".wmv", ".webm")
|
| 15 |
+
if input_audio_path.lower().endswith(video_extensions):
|
| 16 |
+
input_audio_path = convert_video_to_audio_ffmpeg(input_audio_path)
|
| 17 |
+
|
| 18 |
waveform = text_to_audio(
|
| 19 |
audioldm,
|
| 20 |
'placeholder',
|
|
|
|
| 33 |
return filename
|
| 34 |
|
| 35 |
|
| 36 |
+
def convert_video_to_audio_ffmpeg(video_file, output_ext="wav"):
|
| 37 |
+
"""Converts video to audio directly using `ffmpeg` command
|
| 38 |
+
with the help of subprocess module"""
|
| 39 |
+
filename, ext = os.path.splitext(video_file)
|
| 40 |
+
subprocess.call(["ffmpeg", "-y", "-i", video_file, f"{filename}.{output_ext}"],
|
| 41 |
+
stdout=subprocess.DEVNULL,
|
| 42 |
+
stderr=subprocess.STDOUT)
|
| 43 |
+
return f"{filename}.{output_ext}"
|
| 44 |
|
| 45 |
+
webapp = gr.Interface(
|
| 46 |
+
fn = process_fn,
|
| 47 |
# Define your Gradio interface
|
| 48 |
inputs = [
|
| 49 |
gr.Audio(
|
|
|
|
| 76 |
minimum=2.5, maximum=10.0,
|
| 77 |
step=2.5, value=5,
|
| 78 |
label="Duration"
|
| 79 |
+
)
|
| 80 |
+
],
|
| 81 |
|
| 82 |
output = gr.Audio(label="Audio Output", type="filepath", format="wav", elem_id="audio")
|
| 83 |
+
)
|
| 84 |
|
|
|
|
|
|
|
|
|
|
| 85 |
webapp.queue()
|
| 86 |
webapp.launch()
|