Skip to content

Commit

Permalink
fix musicgen ignoring the melody (#154)
Browse files Browse the repository at this point in the history
  • Loading branch information
rsxdalv authored Aug 27, 2023
1 parent 4d39af3 commit be447b5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ Google Colab demo: [![Open In Colab](https://colab.research.google.com/assets/co

## Examples

[audio__bark__continued_generation__2023-05-04_16-07-49_long.webm](https://user-images.githubuserc
ontent.com/6757283/236218842-b9dc253e-05de-49e5-ada9-e714e1e2cbd4.webm)
[audio__bark__continued_generation__2023-05-04_16-07-49_long.webm](https://user-images.githubusercontent.com/6757283/236218842-b9dc253e-05de-49e5-ada9-e714e1e2cbd4.webm)

[audio__bark__continued_generation__2023-05-04_16-09-21_long.webm](https://user-images.githubusercontent.com/6757283/236219228-518d2b70-51a3-4175-af44-b24c01d14932.webm)

Expand All @@ -36,6 +35,9 @@ https://rsxdalv.github.io/bark-speaker-directory/

## Changelog

Aug 27:
* Fix MusicGen ignoring the melody https://github.com/rsxdalv/tts-generation-webui/issues/153

Aug 26:
* Add Send to RVC, Demucs, Vocos buttons to Bark and Vocos

Expand Down
34 changes: 16 additions & 18 deletions src/musicgen/musicgen_tab.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from importlib.metadata import version

AUDIOCRAFT_VERSION = version("audiocraft")

FB_MUSICGEN_MELODY = "facebook/musicgen-melody"

class MusicGenGeneration(TypedDict):
model: str
Expand Down Expand Up @@ -138,7 +138,7 @@ def generate(params: MusicGenGeneration, melody_in: Optional[Tuple[int, np.ndarr
model = params["model"]
text = params["text"]
# due to JSON serialization limitations
params["melody"] = None if model != "melody" else melody_in
params["melody"] = None if model != FB_MUSICGEN_MELODY else melody_in
melody = params["melody"]

global MODEL
Expand All @@ -165,7 +165,7 @@ def generate(params: MusicGenGeneration, melody_in: Optional[Tuple[int, np.ndarr
params["seed"] = parse_or_set_seed(params["seed"], 0)
# generator = torch.Generator(device=MODEL.device).manual_seed(params["seed"])
log_generation_musicgen(params)
if melody:
if model == FB_MUSICGEN_MELODY and melody is not None:
sr, melody = melody[0], torch.from_numpy(melody[1]).to(
MODEL.device
).float().t().unsqueeze(0)
Expand All @@ -181,21 +181,19 @@ def generate(params: MusicGenGeneration, melody_in: Optional[Tuple[int, np.ndarr
return_tokens=True,
# generator=generator,
)
elif model == "facebook/audiogen-medium":
output = MODEL.generate(
descriptions=[text],
progress=True,
# generator=generator,
)
else:
# if AudioGen then don't return tokens
if model == "facebook/audiogen-medium":
output = MODEL.generate(
descriptions=[text],
progress=True,
# generator=generator,
)
else:
output, tokens = MODEL.generate(
descriptions=[text],
progress=True,
return_tokens=True,
# generator=generator,
)
output, tokens = MODEL.generate(
descriptions=[text],
progress=True,
return_tokens=True,
# generator=generator,
)
set_seed(-1)

elapsed = time.time() - start
Expand Down Expand Up @@ -258,7 +256,7 @@ def generation_tab_musicgen():
)
model = gr.Radio(
[
"facebook/musicgen-melody",
FB_MUSICGEN_MELODY,
# "musicgen-melody",
"facebook/musicgen-medium",
# "musicgen-medium",
Expand Down

0 comments on commit be447b5

Please sign in to comment.