jhtonyKoo commited on
Commit
6b95f60
1 Parent(s): 2777fde

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +128 -0
app.py ADDED
@@ -0,0 +1,128 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import json
3
+ import argparse
4
+ import copy
5
+
6
+ import numpy as np
7
+ import matplotlib.pyplot as plt
8
+ import torch
9
+ import tqdm
10
+ import librosa
11
+ import librosa.display
12
+ import soundfile as sf
13
+ import pyloudnorm as pyln
14
+ from dotmap import DotMap
15
+ import gradio as gr
16
+ import pytube as pt
17
+
18
+ from pytube.exceptions import VideoUnavailable
19
+
20
+ from utils import mp3_write, normalize
21
+
22
+ from models import load_model_with_args
23
+ from separate_func import (
24
+ conv_tasnet_separate,
25
+ )
26
+ from utils import db2linear
27
+
28
+
29
+
30
+ def get_audio_from_yt_video(yt_link: str):
31
+ try:
32
+ yt = pt.YouTube(yt_link)
33
+ t = yt.streams.filter(only_audio=True)
34
+ filename = os.path.join(yt_video_dir, binascii.hexlify(os.urandom(8)).decode() + ".wav")
35
+ t[0].download(filename=filename)
36
+ except VideoUnavailable as e:
37
+ warnings.warn(f"Video Not Found at {yt_link} ({e})")
38
+ filename = None
39
+
40
+ return filename, filename
41
+
42
+
43
+ def inference(file_uploaded_in, file_uploaded_ref):
44
+
45
+ output_wav = None
46
+
47
+ return output_wav
48
+
49
+
50
+ with gr.Blocks() as demo:
51
+ gr.HTML(
52
+ """
53
+ <div style="text-align: center; max-width: 700px; margin: 0 auto;">
54
+ <div
55
+ style="
56
+ display: inline-flex;
57
+ align-items: center;
58
+ gap: 0.8rem;
59
+ font-size: 1.75rem;
60
+ "
61
+ >
62
+ <h1 style="font-weight: 900; margin-bottom: 7px;">
63
+ Music Mixing Style Transfer
64
+ </h1>
65
+ </div>
66
+ <p style="margin-bottom: 10px; font-size: 94%">
67
+ Hugging Face interactive demo of the paper "Music Mixing Style Transfer: A Contrastive Learning Approach to Disentangle Audio Effects" (ICASSP 2023).<br>
68
+ a
69
+ </div>
70
+ """
71
+ )
72
+ with gr.Group():
73
+ with gr.Column():
74
+ with gr.Blocks():
75
+ with gr.Tab("Input Music"):
76
+ file_uploaded_in = gr.Audio(label="Input track (mix) to be mixing style transferred", type="filepath")
77
+ with gr.Tab("YouTube url"):
78
+ with gr.Row():
79
+ yt_link_in = gr.Textbox(
80
+ label="Enter YouTube Link of the Video", autofocus=True, lines=3
81
+ )
82
+ yt_btn = gr.Button("Download Audio from YouTube Link", size="lg")
83
+ yt_audio_path = gr.Audio(
84
+ label="Input Audio Extracted from the YouTube Video", interactive=False
85
+ )
86
+ yt_btn.click(
87
+ get_audio_from_yt_video,
88
+ inputs=[yt_link_in],
89
+ outputs=[yt_audio_path, file_uploaded_in],
90
+ )
91
+ with gr.Blocks():
92
+ with gr.Tab("Reference Music"):
93
+ file_uploaded_ref = gr.Audio(label="Reference track (mix) to copy mixing style", type="filepath")
94
+ with gr.Tab("YouTube url"):
95
+ with gr.Row():
96
+ yt_link_ref = gr.Textbox(
97
+ label="Enter YouTube Link of the Video", autofocus=True, lines=3
98
+ )
99
+ yt_btn = gr.Button("Download Audio from YouTube Link", size="lg")
100
+ yt_audio_path = gr.Audio(
101
+ label="Reference Audio Extracted from the YouTube Video", interactive=False
102
+ )
103
+ yt_btn.click(
104
+ get_audio_from_yt_video,
105
+ inputs=[yt_link_ref],
106
+ outputs=[yt_audio_path, file_uploaded_ref],
107
+ )
108
+
109
+ with gr.Group():
110
+ gr.HTML(
111
+ """
112
+ <div> <h3> <center> Mixing Style Transferred Output. </h3> </div>
113
+ """
114
+ )
115
+ # with gr.Row().style(mobile_collapse=False, equal_height=True):
116
+ with gr.Row():
117
+ output_mix = gr.File(label="Download style transferred music track")
118
+ generate_btn.click(
119
+ inference,
120
+ inputs=[file_uploaded_in, file_uploaded_ref],
121
+ outputs=[wav_output],
122
+ )
123
+
124
+
125
+
126
+ if __name__ == "__main__":
127
+ demo.launch(debug=True)
128
+