Spaces:
Running
Running
Commit
·
bb34ae2
1
Parent(s):
e5e6ed7
Updated for new pyharp API.
Browse files- app.py +23 -16
- requirements.txt +1 -1
app.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
from timbre_trap.framework.modules import TimbreTrap
|
| 2 |
-
from pyharp import
|
| 3 |
|
| 4 |
import gradio as gr
|
| 5 |
import torchaudio
|
|
@@ -17,10 +17,11 @@ model = TimbreTrap(sample_rate=22050,
|
|
| 17 |
model.eval()
|
| 18 |
|
| 19 |
model_path_orig = os.path.join('models', 'tt-orig.pt')
|
|
|
|
| 20 |
tt_weights_orig = torch.load(model_path_orig, map_location='cpu')
|
| 21 |
model.load_state_dict(tt_weights_orig)
|
| 22 |
|
| 23 |
-
|
| 24 |
name='Timbre-Trap',
|
| 25 |
description='De-timbre your audio!',
|
| 26 |
author='Frank Cwitkowitz',
|
|
@@ -28,7 +29,7 @@ card = ModelCard(
|
|
| 28 |
)
|
| 29 |
|
| 30 |
|
| 31 |
-
def process_fn(audio_path,
|
| 32 |
# Load the audio with torchaudio
|
| 33 |
audio, fs = torchaudio.load(audio_path)
|
| 34 |
# Average channels to obtain mono-channel
|
|
@@ -41,8 +42,7 @@ def process_fn(audio_path, de_timbre):
|
|
| 41 |
n_samples = audio.size(-1)
|
| 42 |
|
| 43 |
# Obtain transcription or reconstructed spectral coefficients
|
| 44 |
-
coefficients = model.chunked_inference(audio,
|
| 45 |
-
#coefficients = model.inference(audio, de_timbre)
|
| 46 |
|
| 47 |
# Invert coefficients to produce audio
|
| 48 |
audio = model.sliCQ.decode(coefficients)
|
|
@@ -64,32 +64,39 @@ def process_fn(audio_path, de_timbre):
|
|
| 64 |
# Save the audio
|
| 65 |
torchaudio.save(save_path, audio, fs)
|
| 66 |
|
| 67 |
-
|
|
|
|
|
|
|
|
|
|
| 68 |
|
| 69 |
|
| 70 |
# Build Gradio endpoint
|
| 71 |
with gr.Blocks() as demo:
|
| 72 |
-
|
| 73 |
-
gr.Audio(
|
| 74 |
-
label='Audio Input',
|
| 75 |
-
type='filepath'
|
| 76 |
-
),
|
| 77 |
#gr.Checkbox(
|
| 78 |
# value=False,
|
| 79 |
# label='De-Timbre'
|
| 80 |
-
#)
|
| 81 |
gr.Slider(
|
| 82 |
minimum=0,
|
| 83 |
maximum=1,
|
| 84 |
step=1,
|
| 85 |
value=0,
|
| 86 |
label='De-Timbre'
|
| 87 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
]
|
| 89 |
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
|
| 94 |
demo.queue()
|
| 95 |
demo.launch(share=True)
|
|
|
|
| 1 |
from timbre_trap.framework.modules import TimbreTrap
|
| 2 |
+
from pyharp import *
|
| 3 |
|
| 4 |
import gradio as gr
|
| 5 |
import torchaudio
|
|
|
|
| 17 |
model.eval()
|
| 18 |
|
| 19 |
model_path_orig = os.path.join('models', 'tt-orig.pt')
|
| 20 |
+
|
| 21 |
tt_weights_orig = torch.load(model_path_orig, map_location='cpu')
|
| 22 |
model.load_state_dict(tt_weights_orig)
|
| 23 |
|
| 24 |
+
model_card = ModelCard(
|
| 25 |
name='Timbre-Trap',
|
| 26 |
description='De-timbre your audio!',
|
| 27 |
author='Frank Cwitkowitz',
|
|
|
|
| 29 |
)
|
| 30 |
|
| 31 |
|
| 32 |
+
def process_fn(audio_path, transcribe):
|
| 33 |
# Load the audio with torchaudio
|
| 34 |
audio, fs = torchaudio.load(audio_path)
|
| 35 |
# Average channels to obtain mono-channel
|
|
|
|
| 42 |
n_samples = audio.size(-1)
|
| 43 |
|
| 44 |
# Obtain transcription or reconstructed spectral coefficients
|
| 45 |
+
coefficients = model.chunked_inference(audio, transcribe)
|
|
|
|
| 46 |
|
| 47 |
# Invert coefficients to produce audio
|
| 48 |
audio = model.sliCQ.decode(coefficients)
|
|
|
|
| 64 |
# Save the audio
|
| 65 |
torchaudio.save(save_path, audio, fs)
|
| 66 |
|
| 67 |
+
# No output labels
|
| 68 |
+
output_labels = LabelList()
|
| 69 |
+
|
| 70 |
+
return save_path, output_labels
|
| 71 |
|
| 72 |
|
| 73 |
# Build Gradio endpoint
|
| 74 |
with gr.Blocks() as demo:
|
| 75 |
+
components = [
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
#gr.Checkbox(
|
| 77 |
# value=False,
|
| 78 |
# label='De-Timbre'
|
| 79 |
+
#),
|
| 80 |
gr.Slider(
|
| 81 |
minimum=0,
|
| 82 |
maximum=1,
|
| 83 |
step=1,
|
| 84 |
value=0,
|
| 85 |
label='De-Timbre'
|
| 86 |
+
),
|
| 87 |
+
#gr.Number(
|
| 88 |
+
# value=0,
|
| 89 |
+
# label='De-Timbre'
|
| 90 |
+
#),
|
| 91 |
+
#gr.Textbox(
|
| 92 |
+
# value='text',
|
| 93 |
+
# label='De-Timbre'
|
| 94 |
+
#)
|
| 95 |
]
|
| 96 |
|
| 97 |
+
app = build_endpoint(model_card=model_card,
|
| 98 |
+
components=components,
|
| 99 |
+
process_fn=process_fn)
|
| 100 |
|
| 101 |
demo.queue()
|
| 102 |
demo.launch(share=True)
|
requirements.txt
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
-e git+https://github.com/
|
| 2 |
-e git+https://github.com/sony/timbre-trap.git@updates#egg=timbre-trap
|
| 3 |
torchaudio
|
| 4 |
torch
|
|
|
|
| 1 |
+
-e git+https://github.com/TEAMuP-dev/pyharp.git#egg=pyharp
|
| 2 |
-e git+https://github.com/sony/timbre-trap.git@updates#egg=timbre-trap
|
| 3 |
torchaudio
|
| 4 |
torch
|