beyoru/kafka-voice
Viewer • Updated • 1.62k • 7
How to use beyoru/kafka_sesame with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-to-audio", model="beyoru/kafka_sesame") # Load model directly
from transformers import AutoProcessor, AutoModelForTextToWaveform
processor = AutoProcessor.from_pretrained("beyoru/kafka_sesame")
model = AutoModelForTextToWaveform.from_pretrained("beyoru/kafka_sesame")import torch
from transformers import CsmForConditionalGeneration, AutoProcessor
model_id = "beyoru/kafka-sesame"
device = "cuda" if torch.cuda.is_available() else "cpu"
# load the model and the processor
processor = AutoProcessor.from_pretrained(model_id)
model = CsmForConditionalGeneration.from_pretrained(model_id, device_map=device)
model.eval()
model.generation_config.max_length = 250 # big enough to avoid recompilation
model.generation_config.max_new_tokens = None # would take precedence over max_length
model.generation_config.cache_implementation = "static"
model.depth_decoder.generation_config.cache_implementation = "static"
# prepare the inputs
text = "[0]Hello from Sesame." # `[0]` for speaker id 0
inputs = processor(text, add_special_tokens=True).to(device)
# another equivalent way to prepare the inputs
conversation = [
{"role": "0", "content": [{"type": "text", "text": "Hello from Sesame."}]},
]
inputs = processor.apply_chat_template(
conversation,
tokenize=True,
return_dict=True,
).to(device)
# infer the model
@torch.interface_mode()
audio = model.generate(**inputs, output_audio=True)
processor.save_audio(audio, "example_without_context.wav")