Spaces:
Build error
Build error
morkovka1337
commited on
Commit
·
12a5951
1
Parent(s):
cda5020
Update app.py
Browse files
app.py
CHANGED
@@ -15,7 +15,8 @@ logging.basicConfig(
|
|
15 |
logger = logging.getLogger(__name__)
|
16 |
logger.setLevel(logging.DEBUG)
|
17 |
|
18 |
-
|
|
|
19 |
|
20 |
def run(input_file, history, model_size="300M"):
|
21 |
language = "Russian"
|
@@ -26,14 +27,14 @@ def run(input_file, history, model_size="300M"):
|
|
26 |
# the history seems to be not by session anymore, so I'll deactivate this for now
|
27 |
history = []
|
28 |
|
29 |
-
|
30 |
if decoding_type == "LM":
|
31 |
processor = Wav2Vec2ProcessorWithLM.from_pretrained("jonatasgrosman/wav2vec2-large-xlsr-53-russian")
|
32 |
-
asr = pipeline("automatic-speech-recognition", model=
|
33 |
feature_extractor=processor.feature_extractor, decoder=processor.decoder)
|
34 |
else:
|
35 |
processor = Wav2Vec2Processor.from_pretrained("jonatasgrosman/wav2vec2-large-xlsr-53-russian")
|
36 |
-
asr = pipeline("automatic-speech-recognition", model=
|
37 |
feature_extractor=processor.feature_extractor, decoder=None)
|
38 |
|
39 |
transcription = asr(input_file.name, chunk_length_s=5, stride_length_s=1)["text"]
|
@@ -41,7 +42,7 @@ def run(input_file, history, model_size="300M"):
|
|
41 |
logger.info(f"Transcription for {language}-{model_size}-{decoding_type} for {input_file}: {transcription}")
|
42 |
|
43 |
history.append({
|
44 |
-
"model_id":
|
45 |
"language": language,
|
46 |
"model_size": model_size,
|
47 |
"decoding_type": decoding_type,
|
|
|
15 |
logger = logging.getLogger(__name__)
|
16 |
logger.setLevel(logging.DEBUG)
|
17 |
|
18 |
+
model_ID = "jonatasgrosman/wav2vec2-large-xlsr-53-russian"
|
19 |
+
CACHED_MODEL = {"rus": AutoModelForCTC.from_pretrained(model_ID)}
|
20 |
|
21 |
def run(input_file, history, model_size="300M"):
|
22 |
language = "Russian"
|
|
|
27 |
# the history seems to be not by session anymore, so I'll deactivate this for now
|
28 |
history = []
|
29 |
|
30 |
+
model_instance = CACHED_MODEL.get("rus")
|
31 |
if decoding_type == "LM":
|
32 |
processor = Wav2Vec2ProcessorWithLM.from_pretrained("jonatasgrosman/wav2vec2-large-xlsr-53-russian")
|
33 |
+
asr = pipeline("automatic-speech-recognition", model=model_instance, tokenizer=processor.tokenizer,
|
34 |
feature_extractor=processor.feature_extractor, decoder=processor.decoder)
|
35 |
else:
|
36 |
processor = Wav2Vec2Processor.from_pretrained("jonatasgrosman/wav2vec2-large-xlsr-53-russian")
|
37 |
+
asr = pipeline("automatic-speech-recognition", model=model_instance, tokenizer=processor.tokenizer,
|
38 |
feature_extractor=processor.feature_extractor, decoder=None)
|
39 |
|
40 |
transcription = asr(input_file.name, chunk_length_s=5, stride_length_s=1)["text"]
|
|
|
42 |
logger.info(f"Transcription for {language}-{model_size}-{decoding_type} for {input_file}: {transcription}")
|
43 |
|
44 |
history.append({
|
45 |
+
"model_id": model_ID,
|
46 |
"language": language,
|
47 |
"model_size": model_size,
|
48 |
"decoding_type": decoding_type,
|