File size: 1,931 Bytes
68cfefc
 
 
 
 
ae4d7aa
 
fe77cbc
 
 
 
 
 
 
 
 
 
 
1488c83
 
fe77cbc
 
 
 
1488c83
 
 
 
 
 
 
 
fe77cbc
1488c83
 
 
 
 
 
fe77cbc
730f33f
1488c83
 
fe77cbc
 
 
 
 
1488c83
8a95680
cf7e36e
fe77cbc
 
 
 
 
 
1488c83
fe77cbc
 
1488c83
 
 
 
 
fe77cbc
 
 
 
 
 
1488c83
fe77cbc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
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

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 = video_path.rsplit("/", 1)[0]
    video_save_path = str(output_dir) + "/" + str(video_path).replace("/", "__").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:
        os.system("cp %s %s" % (video, video_path))
    
    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()