Gijs Wijngaard
commited on
Commit
Β·
3d568e9
1
Parent(s):
4346fab
with apply template
Browse files
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 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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,
|