Views
No views yet

1from transformers import AutoProcessor, AutoModel
2from transformers import TextStreamer
3import librosa
4import torch
5
6model = AutoModel.from_pretrained(
7 'mesolitica/Malaysian-Qwen2.5-7B-Audio-Instruct',
8 torch_dtype = 'auto',
9 trust_remote_code = True,
10)
11_ = model.cuda()
12processor = AutoProcessor.from_pretrained(
13 'mesolitica/Malaysian-Qwen2.5-7B-Audio-Instruct',
14 trust_remote_code = True,
15)
16
17conversation = [
18 {"role": "user", "content": [
19 {"type": "audio", "audio_url": 'speech/mallm-2.mp3'},
20 {"type": "text", "text": 'translate to french'},
21 ]},
22]
23text = processor.apply_chat_template(conversation, add_generation_prompt=True, tokenize=False)
24audios = []
25for message in conversation:
26 if isinstance(message["content"], list):
27 for ele in message["content"]:
28 if ele["type"] == "audio":
29 audios.append(librosa.load(
30 ele['audio_url'],
31 sr=processor.feature_extractor.sampling_rate)[0]
32 )
33
34inputs = processor(text=text, audios=audios, return_tensors="pt", padding=True).to('cuda')
35inputs['input_features'] = inputs['input_features'].to(model.dtype)
36with torch.no_grad():
37 generate_kwargs = dict(
38 **inputs,
39 max_new_tokens=2048,
40 top_p=0.95,
41 top_k=50,
42 temperature=0.01,
43 do_sample=True,
44 repetition_penalty=1.05,
45 )
46 generation_output = model.generate(**generate_kwargs)
47generate_ids = generation_output[:, inputs.input_ids.size(1):]
48output = processor.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
49print(output)"Les conséquences de l'acte de syirik sont : A - détruire la foi ; B - commettre un grand péché ; C - être murtad ; D - recevoir le châtiment dans l'au-delà"1import base64
2from openai import OpenAI
3
4openai_api_key = "EMPTY"
5openai_api_base = "http://localhost:8001/v1"
6
7client = OpenAI(
8 api_key=openai_api_key,
9 base_url=openai_api_base,
10)
11
12with open('speech/mallm-2.mp3', 'rb') as fopen:
13 audio_base64 = base64.b64encode(fopen.read()).decode('utf-8')
14
15model = 'mesolitica/Malaysian-Qwen2.5-7B-Audio-Instruct'
16
17chat_completion_from_base64 = client.chat.completions.create(
18 messages=[{
19 "role": "user",
20 "content": [
21 {
22 "type": "input_audio",
23 "input_audio": {
24 "data": audio_base64,
25 "format": "mp3"
26 },
27 },
28 {
29 "type": "text",
30 "text": "explain the audio"
31 },
32 ],
33
34 }],
35 model=model,
36 max_completion_tokens=1024,
37 temperature=0.6,
38 top_p=0.9,
39)ChatCompletion(id='chatcmpl-4343d53b608249c49cc56257b7fc6c72', choices=[Choice(finish_reason='stop', index=0, logprobs=None, message=ChatCompletionMessage(content='The speaker is listing the consequences of shirk (polytheism) in a straightforward and matter-of-fact manner. Here’s a breakdown of each point:\n\n1. **A. Rosak akidah (Rusak iman)**: This means "ruining one\'s faith." The speaker is emphasizing that shirk directly affects one\'s spiritual well-being and faith.\n\n2. **B. Berdosa besar (Berbuat dosa besar)**: This translates to "committing major sins." The speaker is highlighting that shirk is considered a grave sin in Islam, which can lead to severe spiritual consequences.\n\n3. **C. Menjadi murtad (Menjadi muhaddid)**: This means "becoming an apostate." The speaker is pointing out that shirk can lead to a person being labeled as an apostate, which has serious legal and social implications.\n\n4. **D. Mendapat azab di akhirat (Menerima azab di akhirat)**: This translates to "receiving punishment in the afterlife." The speaker is indicating that the ultimate consequence of shirk is eternal punishment in the hereafter.\n\nThe tone is serious and educational, typical of religious teachings where the gravity of certain actions is emphasized. The speaker is likely addressing an audience that is familiar with Islamic concepts and is providing a clear and concise explanation of the consequences of shirk.', refusal=None, role='assistant', annotations=None, audio=None, function_call=None, tool_calls=[], reasoning_content=None), stop_reason=None)], created=1750396026, model='mesolitica/Malaysian-Qwen2.5-7B-Audio-Instruct', object='chat.completion', service_tier=None, system_fingerprint=None, usage=CompletionUsage(completion_tokens=285, prompt_tokens=569, total_tokens=854, completion_tokens_details=None, prompt_tokens_details=None), prompt_logprobs=None, kv_transfer_params=None)