import librosa, torch
from peft import PeftModel
from transformers import AutoProcessor, Qwen2AudioForConditionalGeneration
base = "Qwen/Qwen2-Audio-7B-Instruct"
processor = AutoProcessor.from_pretrained(base)
model = PeftModel.from_pretrained(
Qwen2AudioForConditionalGeneration.from_pretrained(base, torch_dtype=torch.float16, device_map={"": 0}),
"mclemcrew/Qwen2-Audio-MixAssist-LoRA",
)
audio, _ = librosa.load("my_mix_segment.wav", sr=16000)
conversation = [
{"role": "system", "content": "You are an expert audio engineer assisting with music production and mixing. Provide clear, specific advice on audio engineering techniques, mixing adjustments, and production decisions based on the audio samples and the user's questions. Focus on practical, actionable guidance."},
{"role": "user", "content": [
{"type": "audio", "audio_url": "my_mix_segment.wav"},
{"type": "text", "text": "The vocals feel buried in the chorus. What should I do?"},
]},
]
text = processor.apply_chat_template(conversation, tokenize=False, add_generation_prompt=True)
inputs = processor(text=text, audios=[audio], sampling_rate=16000, return_tensors="pt").to(model.device)
out = model.generate(**inputs, do_sample=True, temperature=0.7, top_k=20, top_p=0.5,
repetition_penalty=1.1, max_new_tokens=300)
print(processor.batch_decode(out[:, inputs["input_ids"].size(1):], skip_special_tokens=True)[0])