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

Question-Answering Task #99

Open
jrohsc opened this issue Nov 27, 2024 · 2 comments
Open

Question-Answering Task #99

jrohsc opened this issue Nov 27, 2024 · 2 comments

Comments

@jrohsc
Copy link

jrohsc commented Nov 27, 2024

Hi,

How can I use Qwen2-Audio model on a speech question-answering task? I tried both providing and not providing the instruction but it seems like the model is only transcribing the audio input.

@hsoftxl
Copy link

hsoftxl commented Dec 10, 2024

what is you code?

@jrohsc
Copy link
Author

jrohsc commented Feb 2, 2025

import torch
from transformers import AutoProcessor, Qwen2AudioForConditionalGeneration
import librosa

device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
print("Using device:", device)

model = Qwen2AudioForConditionalGeneration.from_pretrained("Qwen/Qwen2-Audio-7B", trust_remote_code=True)
model = model.to(device)
processor = AutoProcessor.from_pretrained("Qwen/Qwen2-Audio-7B", trust_remote_code=True)

prompt = "<|audio_bos|><|AUDIO|><|audio_eos|> "
path = "path_to_audio_file.mp3"

audio, sr = librosa.load(path, sr=processor.feature_extractor.sampling_rate)
inputs = processor(text=prompt, audios=audio, return_tensors="pt").to(device)

with torch.no_grad():
generated_ids = model.generate(**inputs, max_length=256)
generated_ids = generated_ids[:, inputs.input_ids.size(1):]
response = processor.batch_decode(generated_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]

print(response)

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

No branches or pull requests

2 participants