Spaces:
Running
on
Zero
Running
on
Zero
Gijs Wijngaard
commited on
Commit
·
43faff9
1
Parent(s):
1e328fc
init
Browse files
app.py
CHANGED
|
@@ -12,7 +12,7 @@ model = Qwen2AudioForConditionalGeneration.from_pretrained(MODEL_ID, device_map=
|
|
| 12 |
|
| 13 |
|
| 14 |
@spaces.GPU
|
| 15 |
-
def run_qwen2audio(audio_path: str, instruction: str
|
| 16 |
if not audio_path:
|
| 17 |
return "Please upload an audio file."
|
| 18 |
|
|
@@ -36,7 +36,7 @@ def run_qwen2audio(audio_path: str, instruction: str, max_tokens: int = 256) ->
|
|
| 36 |
inputs = processor(text=text, audio=audios, return_tensors="pt", padding=True)
|
| 37 |
inputs = inputs.to(model.device)
|
| 38 |
|
| 39 |
-
output_ids = model.generate(**inputs,
|
| 40 |
output_ids = output_ids[:, inputs.input_ids.size(1):]
|
| 41 |
response = processor.batch_decode(output_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
|
| 42 |
return response
|
|
@@ -50,12 +50,11 @@ with gr.Blocks(title="Qwen2-Audio Demo") as demo:
|
|
| 50 |
with gr.Column():
|
| 51 |
audio_input = gr.Audio(type="filepath", label="Upload Audio")
|
| 52 |
instruction = gr.Textbox(label="Instruction", value="Transcribe the audio.")
|
| 53 |
-
max_tokens = gr.Slider(64, 1024, value=256, step=32, label="Max Tokens")
|
| 54 |
submit_btn = gr.Button("Run", variant="primary")
|
| 55 |
with gr.Column():
|
| 56 |
output_text = gr.Textbox(label="Response", lines=12)
|
| 57 |
|
| 58 |
-
submit_btn.click(run_qwen2audio, [audio_input, instruction
|
| 59 |
|
| 60 |
|
| 61 |
if __name__ == "__main__":
|
|
|
|
| 12 |
|
| 13 |
|
| 14 |
@spaces.GPU
|
| 15 |
+
def run_qwen2audio(audio_path: str, instruction: str) -> str:
|
| 16 |
if not audio_path:
|
| 17 |
return "Please upload an audio file."
|
| 18 |
|
|
|
|
| 36 |
inputs = processor(text=text, audio=audios, return_tensors="pt", padding=True)
|
| 37 |
inputs = inputs.to(model.device)
|
| 38 |
|
| 39 |
+
output_ids = model.generate(**inputs, max_new_tokens=4096)
|
| 40 |
output_ids = output_ids[:, inputs.input_ids.size(1):]
|
| 41 |
response = processor.batch_decode(output_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
|
| 42 |
return response
|
|
|
|
| 50 |
with gr.Column():
|
| 51 |
audio_input = gr.Audio(type="filepath", label="Upload Audio")
|
| 52 |
instruction = gr.Textbox(label="Instruction", value="Transcribe the audio.")
|
|
|
|
| 53 |
submit_btn = gr.Button("Run", variant="primary")
|
| 54 |
with gr.Column():
|
| 55 |
output_text = gr.Textbox(label="Response", lines=12)
|
| 56 |
|
| 57 |
+
submit_btn.click(run_qwen2audio, [audio_input, instruction], output_text)
|
| 58 |
|
| 59 |
|
| 60 |
if __name__ == "__main__":
|