Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add YuE (music gen) from fal.ai #2801

Merged
merged 6 commits into from
Jan 31, 2025
Merged

Add YuE (music gen) from fal.ai #2801

merged 6 commits into from
Jan 31, 2025

Conversation

Wauplin
Copy link
Contributor

@Wauplin Wauplin commented Jan 29, 2025

Similar to huggingface/huggingface.js#1148.

Will keep it as draft for now. I mostly wanted to see how that integration would work given that it doesn't use the same parameters as we have for text_to_speech (has an extra "genres" parameters). For now I added it to the signature + docstring but it's not compliant with https://github.com/huggingface/huggingface.js/blob/main/packages/tasks/src/tasks/text-to-speech/spec/input.json.

Another possibility is to add a text-to-audio or text-to-music but that seems premature given it's a single model, single provider and still experimental. Will have to wait more example before an harmonization.

Working code example:

import os
from huggingface_hub import InferenceClient

lyrics = """
[verse]
In the town where I was born
Lived a man who sailed to sea
And he told us of his life
In the land of submarines
So we sailed on to the sun
'Til we found a sea of green
And we lived beneath the waves
In our yellow submarine

[chorus]
We all live in a yellow submarine
Yellow submarine, yellow submarine
We all live in a yellow submarine
Yellow submarine, yellow submarine
"""
genres = "pavarotti-style tenor voice"

t0 = time.time()
client = InferenceClient(
    provider="fal-ai",
    model="m-a-p/YuE-s1-7B-anneal-en-cot",
    api_key=os.getenv("FAL_AI_KEY"),
)
audio = client.text_to_speech(lyrics, extra_parameters={"genres": genres})
with open("output.mp3", "wb") as f:
    f.write(audio)
DnwXm1UGLGJZGPPFGbnL.mp4

(what a masterpiece, I know)

Process took 594s (~10min) to run on fal.ai. This means it will fail if we go through HF proxy as there is a 60s timeout. For now only works when passing a FAL_AI key directly. This can be fixed using async/queuing mechanism but out of scope for this PR.

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@hanouticelina
Copy link
Contributor

maybe genres can be passed inside extra_parameters when #2812 is merged.

@Wauplin
Copy link
Contributor Author

Wauplin commented Jan 31, 2025

Waiting for it! 😄

@hanouticelina
Copy link
Contributor

here you go : 07e1adb 😄

@Wauplin Wauplin marked this pull request as ready for review January 31, 2025 12:07
def _prepare_payload(self, inputs: Any, parameters: Dict[str, Any]) -> Dict[str, Any]:
parameters = {k: v for k, v in parameters.items() if v is not None}
return {
"lyrics": inputs,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder in the future how we will distinguish between "lyrics" (for music-gen) and "text" (for text-to-speech). For now there's only 1 model so let's do it this way.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, same issue with replicate for this task 😕

@Wauplin Wauplin requested a review from hanouticelina January 31, 2025 12:13
@Wauplin Wauplin changed the title YuE first test (fal.ai provider) Add YuE (music gen) from fal.ai Jan 31, 2025
Copy link
Contributor

@hanouticelina hanouticelina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you!

@Wauplin Wauplin merged commit 63aada5 into main Jan 31, 2025
17 checks passed
@Wauplin Wauplin deleted the fal-text-to-speech branch January 31, 2025 13:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants