Spaces:
Sleeping
Sleeping
Move the prompts onto the model's device and cut the timbre prompt to 2 s, as the authors' demo does.
Browse files
app.py
CHANGED
|
@@ -117,12 +117,15 @@ def generate_audio(timbre_path, rhythm_path, cfg_scale, top_p, mask_temperature,
|
|
| 117 |
rhythm_in = load_audio(rhythm_path)
|
| 118 |
original_sr = rhythm_in.sample_rate
|
| 119 |
|
| 120 |
-
timbre_sig = load_audio(timbre_path).resample(sample_rate)
|
| 121 |
-
rhythm_sig = rhythm_in.resample(sample_rate)
|
| 122 |
timbre_sig.ensure_max_of_audio()
|
| 123 |
rhythm_sig.ensure_max_of_audio()
|
| 124 |
|
|
|
|
|
|
|
| 125 |
prefix_dur = int(LOADED["max_duration"] / 3)
|
|
|
|
| 126 |
timbre_tokens = tokenizer.encode(timbre_sig)
|
| 127 |
rhythm_tokens = tokenizer.encode(rhythm_sig)
|
| 128 |
tokens = torch.cat([timbre_tokens.tokens, rhythm_tokens.tokens], dim=-1)
|
|
@@ -191,7 +194,7 @@ if __name__ == "__main__":
|
|
| 191 |
with gr.Blocks(title="TRIA") as demo:
|
| 192 |
timbre_in = gr.Audio(type="filepath", label="Timbre Prompt").harp_required(True).set_info((
|
| 193 |
"A recording of the drum sounds you want, such as a kit or a loop. "
|
| 194 |
-
"This decides what the result sounds like."
|
| 195 |
))
|
| 196 |
rhythm_in = gr.Audio(type="filepath", label="Rhythm Prompt").harp_required(True).set_info((
|
| 197 |
"A recording of the groove you want, which can be tapped or "
|
|
|
|
| 117 |
rhythm_in = load_audio(rhythm_path)
|
| 118 |
original_sr = rhythm_in.sample_rate
|
| 119 |
|
| 120 |
+
timbre_sig = load_audio(timbre_path).resample(sample_rate).to(DEVICE)
|
| 121 |
+
rhythm_sig = rhythm_in.clone().resample(sample_rate).to(DEVICE)
|
| 122 |
timbre_sig.ensure_max_of_audio()
|
| 123 |
rhythm_sig.ensure_max_of_audio()
|
| 124 |
|
| 125 |
+
# The model was trained with at most a third of its buffer as the timbre
|
| 126 |
+
# prefix, and the authors' demo cuts the timbre prompt to it as well
|
| 127 |
prefix_dur = int(LOADED["max_duration"] / 3)
|
| 128 |
+
timbre_sig.truncate_samples(int(prefix_dur * sample_rate))
|
| 129 |
timbre_tokens = tokenizer.encode(timbre_sig)
|
| 130 |
rhythm_tokens = tokenizer.encode(rhythm_sig)
|
| 131 |
tokens = torch.cat([timbre_tokens.tokens, rhythm_tokens.tokens], dim=-1)
|
|
|
|
| 194 |
with gr.Blocks(title="TRIA") as demo:
|
| 195 |
timbre_in = gr.Audio(type="filepath", label="Timbre Prompt").harp_required(True).set_info((
|
| 196 |
"A recording of the drum sounds you want, such as a kit or a loop. "
|
| 197 |
+
"This decides what the result sounds like. Only its first 2 seconds are used."
|
| 198 |
))
|
| 199 |
rhythm_in = gr.Audio(type="filepath", label="Rhythm Prompt").harp_required(True).set_info((
|
| 200 |
"A recording of the groove you want, which can be tapped or "
|