Omar Sanseviero
commited on
Commit
·
7464ce6
1
Parent(s):
e73a3e4
Update model.py
Browse files
model.py
CHANGED
|
@@ -1,17 +1,15 @@
|
|
| 1 |
import numpy as np
|
| 2 |
from transformers import AutomaticSpeechRecognitionPipeline, AutoTokenizer, Wav2Vec2FeatureExtractor, Wav2Vec2ForCTC
|
| 3 |
from typing import Dict
|
| 4 |
-
from pathlib import Path
|
| 5 |
|
| 6 |
class PreTrainedModel():
|
| 7 |
-
def __init__(self):
|
| 8 |
"""
|
| 9 |
Loads model and tokenizer from local directory
|
| 10 |
"""
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
extractor = Wav2Vec2FeatureExtractor.from_pretrained(current_file_path.parent)
|
| 15 |
|
| 16 |
self.model = AutomaticSpeechRecognitionPipeline(model=model, feature_extractor=extractor, tokenizer=tokenizer)
|
| 17 |
def __call__(self, inputs)-> Dict[str, str]:
|
|
|
|
| 1 |
import numpy as np
|
| 2 |
from transformers import AutomaticSpeechRecognitionPipeline, AutoTokenizer, Wav2Vec2FeatureExtractor, Wav2Vec2ForCTC
|
| 3 |
from typing import Dict
|
|
|
|
| 4 |
|
| 5 |
class PreTrainedModel():
|
| 6 |
+
def __init__(self, path):
|
| 7 |
"""
|
| 8 |
Loads model and tokenizer from local directory
|
| 9 |
"""
|
| 10 |
+
model = Wav2Vec2ForCTC.from_pretrained(path)
|
| 11 |
+
tokenizer = AutoTokenizer.from_pretrained(path)
|
| 12 |
+
extractor = Wav2Vec2FeatureExtractor.from_pretrained(path)
|
|
|
|
| 13 |
|
| 14 |
self.model = AutomaticSpeechRecognitionPipeline(model=model, feature_extractor=extractor, tokenizer=tokenizer)
|
| 15 |
def __call__(self, inputs)-> Dict[str, str]:
|