Spaces:
Running
Running
import os | |
try: | |
import torchaudio | |
except ImportError: | |
os.system("cd ./F5-TTS; pip install -e .") | |
import spaces | |
import logging | |
from datetime import datetime | |
from pathlib import Path | |
import gradio as gr | |
import torch | |
import torchaudio | |
import tempfile | |
import requests | |
import shutil | |
log = logging.getLogger() | |
#@spaces.GPU(duration=120) | |
def video_to_audio(video: gr.Video, prompt: str): | |
video_path = tempfile.NamedTemporaryFile(delete=False, suffix='.mp4').name | |
output_dir = os.path.dirname(video_path) | |
video_save_path = os.path.join(str(output_dir), "__" + os.path.basename(video_path).strip(".") + ".mp4") | |
print("paths", video, video_path, output_dir, video_save_path) | |
if video.startswith("http"): | |
data = requests.get(video, timeout=60).content | |
with open(video_path, "wb") as fw: | |
fw.write(data) | |
else: | |
shutil.copy(video, video_path) | |
if prompt == "": | |
os.system("cd ./MMAudio; python ./demo.py --variant small_44k --output %s --video %s --calc_energy 1" % (output_dir, video_path)) | |
else: | |
os.system("cd ./MMAudio; python ./demo.py --variant small_44k --output %s --video %s --prompt %s --calc_energy 1" % (output_dir, video_path, prompt)) | |
return video_save_path | |
video_to_audio_tab = gr.Interface( | |
fn=video_to_audio, | |
description=""" | |
Project page: <a href="https://acappemin.github.io/DeepAudio-V1.github.io">https://acappemin.github.io/DeepAudio-V1.github.io</a><br> | |
Code: <a href="https://github.com/acappemin/DeepAudio-V1">https://github.com/acappemin/DeepAudio-V1</a><br> | |
""", | |
inputs=[ | |
gr.Video(), | |
gr.Text(label='Prompt'), | |
], | |
outputs='playable_video', | |
cache_examples=False, | |
title='Video-to-Audio', | |
examples=[ | |
[ | |
'./tests/0235.mp4', | |
'', | |
], | |
[ | |
'./tests/0778.mp4', | |
'', | |
], | |
]) | |
if __name__ == "__main__": | |
gr.TabbedInterface([video_to_audio_tab], ['Video-to-Audio']).launch() | |