Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
limitations under the License.
"""
import re
import os

from ...representation import CharacterRecognitionPrediction
from ...utils import UnsupportedPackage, extract_image_representations
Expand Down Expand Up @@ -121,7 +122,7 @@ def _initialize_pipeline(self, config):
except ImportError as import_error:
UnsupportedPackage("openvino_genai", import_error.msg).raise_error(self.__class__.__name__)

model_dir = config.get("_models", [None])[0]
model_dir = get_model_dir(config)
device = config.get("_device", "CPU")
pipeline = ov_genai.WhisperPipeline(str(model_dir), device=device)
return pipeline
Expand Down Expand Up @@ -169,7 +170,7 @@ def _initialize_pipeline(self, config):
UnsupportedPackage("optimum.intel.openvino", import_error.msg).raise_error(self.__class__.__name__)

device = config.get("_device", "CPU")
model_dir = config.get("_models", [None])[0]
model_dir = get_model_dir(config)
ov_model = OVModelForSpeechSeq2Seq.from_pretrained(str(model_dir)).to(device)
ov_processor = AutoProcessor.from_pretrained(str(model_dir))

Expand All @@ -184,3 +185,12 @@ def _get_predictions(self, data, identifiers, input_meta):
sampling_rate = input_meta[0].get("sample_rate")
sample = {"path": identifiers[0], "array": data[0], "sampling_rate": sampling_rate}
return self.pipeline(sample, return_timestamps=True)["text"]



def get_model_dir(config):
model_path = config.get("_models", [None])[0]

if os.path.isfile(model_path):
return os.path.dirname(model_path)
return model_path
Loading