Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,23 +5,24 @@ import yt_dlp as youtube_dl
|
|
| 5 |
from transformers import pipeline
|
| 6 |
from transformers.pipelines.audio_utils import ffmpeg_read
|
| 7 |
from transformers import MBartForConditionalGeneration, MBart50TokenizerFast
|
|
|
|
| 8 |
|
| 9 |
|
| 10 |
import tempfile
|
| 11 |
import os
|
| 12 |
|
| 13 |
-
MODEL_NAME = "
|
| 14 |
BATCH_SIZE = 8
|
| 15 |
FILE_LIMIT_MB = 1000
|
| 16 |
|
| 17 |
device = 0 if torch.cuda.is_available() else "cpu"
|
| 18 |
|
| 19 |
-
pipe = pipeline(
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
)
|
| 25 |
|
| 26 |
model = MBartForConditionalGeneration.from_pretrained("sanjitaa/mbart-many-to-many")
|
| 27 |
tokenizer = MBart50TokenizerFast.from_pretrained("sanjitaa/mbart-many-to-many")
|
|
@@ -30,7 +31,9 @@ def translate(inputs, task):
|
|
| 30 |
if inputs is None:
|
| 31 |
raise gr.Error("No audio file submitted! Please upload or record an audio file before submitting your request.")
|
| 32 |
|
| 33 |
-
text = pipe(inputs, batch_size=BATCH_SIZE, generate_kwargs={"task": task}, return_timestamps=True)["text"]
|
|
|
|
|
|
|
| 34 |
|
| 35 |
encoded_text = tokenizer(text, return_tensors="pt")
|
| 36 |
tokenizer.src_lang = "en_XX"
|
|
|
|
| 5 |
from transformers import pipeline
|
| 6 |
from transformers.pipelines.audio_utils import ffmpeg_read
|
| 7 |
from transformers import MBartForConditionalGeneration, MBart50TokenizerFast
|
| 8 |
+
from faster_whisper import WhisperModel
|
| 9 |
|
| 10 |
|
| 11 |
import tempfile
|
| 12 |
import os
|
| 13 |
|
| 14 |
+
MODEL_NAME = "medium"
|
| 15 |
BATCH_SIZE = 8
|
| 16 |
FILE_LIMIT_MB = 1000
|
| 17 |
|
| 18 |
device = 0 if torch.cuda.is_available() else "cpu"
|
| 19 |
|
| 20 |
+
# pipe = pipeline(
|
| 21 |
+
# task="automatic-speech-recognition",
|
| 22 |
+
# model=MODEL_NAME,
|
| 23 |
+
# chunk_length_s=30,
|
| 24 |
+
# device=device,
|
| 25 |
+
# )
|
| 26 |
|
| 27 |
model = MBartForConditionalGeneration.from_pretrained("sanjitaa/mbart-many-to-many")
|
| 28 |
tokenizer = MBart50TokenizerFast.from_pretrained("sanjitaa/mbart-many-to-many")
|
|
|
|
| 31 |
if inputs is None:
|
| 32 |
raise gr.Error("No audio file submitted! Please upload or record an audio file before submitting your request.")
|
| 33 |
|
| 34 |
+
#text = pipe(inputs, batch_size=BATCH_SIZE, generate_kwargs={"task": task}, return_timestamps=True)["text"]
|
| 35 |
+
ts_model = WhisperModel(MODEL_NAME, device = device, compute_type = "int8")
|
| 36 |
+
text = ts_model.transcribe(inputs, task = "translate")
|
| 37 |
|
| 38 |
encoded_text = tokenizer(text, return_tensors="pt")
|
| 39 |
tokenizer.src_lang = "en_XX"
|