Gijs Wijngaard commited on
Commit
3d568e9
Β·
1 Parent(s): 4346fab

with apply template

Browse files
Files changed (1) hide show
  1. app.py +17 -9
app.py CHANGED
@@ -29,15 +29,23 @@ def run_phi4(audio_path: str, instruction: str) -> str:
29
  if not audio_path:
30
  return "Please upload an audio file."
31
 
32
- audio, samplerate = sf.read(audio_path)
33
-
34
- user_prompt = "<|user|>"
35
- assistant_prompt = "<|assistant|>"
36
- prompt_suffix = "<|end|>"
37
-
38
- prompt = f"{user_prompt}<|audio_1|>{instruction}{prompt_suffix}{assistant_prompt}"
39
-
40
- inputs = processor(text=prompt, audios=[(audio, samplerate)], return_tensors="pt").to(model.device)
 
 
 
 
 
 
 
 
41
 
42
  output_ids = model.generate(
43
  **inputs,
 
29
  if not audio_path:
30
  return "Please upload an audio file."
31
 
32
+ messages = [
33
+ {
34
+ "role": "user",
35
+ "content": [
36
+ {"type": "audio", "url": audio_path},
37
+ {"type": "text", "text": "Transcribe the audio to text, and then translate the audio to French. Use <sep> as a separator between the origina transcript and the translation."},
38
+ ],
39
+ },
40
+ ]
41
+
42
+ inputs = processor.apply_chat_template(
43
+ messages,
44
+ add_generation_prompt=True,
45
+ tokenize=True,
46
+ return_dict=True,
47
+ return_tensors="pt",
48
+ ).to(model.device)
49
 
50
  output_ids = model.generate(
51
  **inputs,