Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,9 +1,39 @@
|
|
1 |
import gradio as gr
|
2 |
-
import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
-
model = whisper.load_model("large")
|
5 |
def predict(audio, language):
|
6 |
-
|
|
|
|
|
|
|
|
|
|
|
7 |
return result["text"]
|
8 |
|
9 |
demo = gr.Interface(
|
|
|
1 |
import gradio as gr
|
2 |
+
import torch
|
3 |
+
from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor, pipeline
|
4 |
+
|
5 |
+
|
6 |
+
|
7 |
+
|
8 |
+
device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
9 |
+
torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
|
10 |
+
|
11 |
+
model_id = "openai/whisper-large-v3"
|
12 |
+
|
13 |
+
model = AutoModelForSpeechSeq2Seq.from_pretrained(
|
14 |
+
model_id, torch_dtype=torch_dtype, low_cpu_mem_usage=True, use_safetensors=True
|
15 |
+
)
|
16 |
+
model.to(device)
|
17 |
+
|
18 |
+
processor = AutoProcessor.from_pretrained(model_id)
|
19 |
+
|
20 |
+
pipe = pipeline(
|
21 |
+
"automatic-speech-recognition",
|
22 |
+
model=model,
|
23 |
+
tokenizer=processor.tokenizer,
|
24 |
+
feature_extractor=processor.feature_extractor,
|
25 |
+
torch_dtype=torch_dtype,
|
26 |
+
device=device,
|
27 |
+
)
|
28 |
+
|
29 |
|
|
|
30 |
def predict(audio, language):
|
31 |
+
generate_kwargs = {
|
32 |
+
"task": 'translate',
|
33 |
+
"language": language,
|
34 |
+
"return_timestamps": True,
|
35 |
+
}
|
36 |
+
result = result = pipe(audio, generate_kwargs=generate_kwargs)
|
37 |
return result["text"]
|
38 |
|
39 |
demo = gr.Interface(
|