Spaces:
Sleeping
Sleeping
yellowcandle
commited on
Merge branch 'dev-model-list'
Browse files
app.py
CHANGED
@@ -3,15 +3,16 @@ import gradio as gr
|
|
3 |
# Use a pipeline as a high-level helper
|
4 |
import torch
|
5 |
from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor, pipeline
|
6 |
-
from datasets import load_dataset
|
7 |
|
8 |
@spaces.GPU(duration=120)
|
9 |
-
def transcribe_audio(audio):
|
|
|
|
|
|
|
10 |
device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
11 |
torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
|
12 |
|
13 |
-
model_id = "openai/whisper-large-v3"
|
14 |
-
|
15 |
model = AutoModelForSpeechSeq2Seq.from_pretrained(
|
16 |
model_id, torch_dtype=torch_dtype, low_cpu_mem_usage=True, use_safetensors=True
|
17 |
)
|
@@ -36,7 +37,7 @@ def transcribe_audio(audio):
|
|
36 |
|
37 |
|
38 |
demo = gr.Interface(fn=transcribe_audio,
|
39 |
-
inputs=gr.Audio(sources="upload", type="filepath"),
|
40 |
outputs="text")
|
41 |
demo.launch()
|
42 |
|
|
|
3 |
# Use a pipeline as a high-level helper
|
4 |
import torch
|
5 |
from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor, pipeline
|
6 |
+
# from datasets import load_dataset
|
7 |
|
8 |
@spaces.GPU(duration=120)
|
9 |
+
def transcribe_audio(audio, model_id):
|
10 |
+
if audio is None:
|
11 |
+
return "Please upload an audio file."
|
12 |
+
|
13 |
device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
14 |
torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
|
15 |
|
|
|
|
|
16 |
model = AutoModelForSpeechSeq2Seq.from_pretrained(
|
17 |
model_id, torch_dtype=torch_dtype, low_cpu_mem_usage=True, use_safetensors=True
|
18 |
)
|
|
|
37 |
|
38 |
|
39 |
demo = gr.Interface(fn=transcribe_audio,
|
40 |
+
inputs=[gr.Audio(sources="upload", type="filepath"), gr.Dropdown(choices=["openai/whisper-large-v3", "alvanlii/whisper-small-cantonese"])],
|
41 |
outputs="text")
|
42 |
demo.launch()
|
43 |
|