Spaces:
Sleeping
Sleeping
Commit
•
e2b6220
1
Parent(s):
243ff9b
Update demos/musicgen_app.py
Browse files- demos/musicgen_app.py +18 -4
demos/musicgen_app.py
CHANGED
@@ -18,6 +18,7 @@ from tempfile import NamedTemporaryFile
|
|
18 |
import time
|
19 |
import typing as tp
|
20 |
import warnings
|
|
|
21 |
|
22 |
from einops import rearrange
|
23 |
import torch
|
@@ -209,9 +210,22 @@ def predict_full(secret_token, model, model_path, decoder, text, melody, duratio
|
|
209 |
[text], [melody], duration, progress=True,
|
210 |
top_k=topk, top_p=topp, temperature=temperature, cfg_coef=cfg_coef,
|
211 |
gradio_progress=progress)
|
|
|
|
|
212 |
if USE_DIFFUSION:
|
213 |
-
|
214 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
215 |
|
216 |
def toggle_audio_src(choice):
|
217 |
if choice == "mic":
|
@@ -274,8 +288,8 @@ def ui_full(launch_kwargs):
|
|
274 |
temperature = gr.Number(label="Temperature", value=1.0, interactive=True)
|
275 |
cfg_coef = gr.Number(label="Classifier Free Guidance", value=3.0, interactive=True)
|
276 |
with gr.Column():
|
277 |
-
audio_output = gr.Audio(label="Generated Music (wav)"
|
278 |
-
audio_diffusion = gr.
|
279 |
submit.click(toggle_diffusion, decoder, [audio_diffusion], queue=False,
|
280 |
show_progress=False).then(predict_full, inputs=[secret_token, model, model_path, decoder, text, melody, duration, topk, topp,
|
281 |
temperature, cfg_coef],
|
|
|
18 |
import time
|
19 |
import typing as tp
|
20 |
import warnings
|
21 |
+
import base64
|
22 |
|
23 |
from einops import rearrange
|
24 |
import torch
|
|
|
210 |
[text], [melody], duration, progress=True,
|
211 |
top_k=topk, top_p=topp, temperature=temperature, cfg_coef=cfg_coef,
|
212 |
gradio_progress=progress)
|
213 |
+
|
214 |
+
wav_path = wavs[0]
|
215 |
if USE_DIFFUSION:
|
216 |
+
wav_path = wavs[1]
|
217 |
+
|
218 |
+
|
219 |
+
wav_base64 = ""
|
220 |
+
|
221 |
+
# Read the content of the video file and encode it to base64
|
222 |
+
with open(wav_path, "rb") as wav_file:
|
223 |
+
wav_base64 = base64.b64encode(wav_file.read()).decode('utf-8')
|
224 |
+
|
225 |
+
# Prepend the appropriate data URI header with MIME type
|
226 |
+
wav_base64_data_uri = 'data:audio/wav;base64,' + wav_base64
|
227 |
+
|
228 |
+
return wav_base64_data_uri
|
229 |
|
230 |
def toggle_audio_src(choice):
|
231 |
if choice == "mic":
|
|
|
288 |
temperature = gr.Number(label="Temperature", value=1.0, interactive=True)
|
289 |
cfg_coef = gr.Number(label="Classifier Free Guidance", value=3.0, interactive=True)
|
290 |
with gr.Column():
|
291 |
+
audio_output = gr.Audio(label="Generated Music (wav)")
|
292 |
+
audio_diffusion = gr.Textbox(label="MultiBand Diffusion Decoder (wav)")
|
293 |
submit.click(toggle_diffusion, decoder, [audio_diffusion], queue=False,
|
294 |
show_progress=False).then(predict_full, inputs=[secret_token, model, model_path, decoder, text, melody, duration, topk, topp,
|
295 |
temperature, cfg_coef],
|