Skip to content

Commit

Permalink
compatible with local whisper model
Browse files Browse the repository at this point in the history
  • Loading branch information
harry committed Apr 11, 2024
1 parent 759c1ce commit 1c7d7e1
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions app/services/subtitle.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import os.path
import re

from faster_whisper import WhisperModel
Expand All @@ -17,8 +18,13 @@
def create(audio_file, subtitle_file: str = ""):
global model
if not model:
logger.info(f"loading model: {model_size}, device: {device}, compute_type: {compute_type}")
model = WhisperModel(model_size_or_path=model_size,
model_path = f"{utils.root_dir()}/models/whisper-{model_size}"
model_bin_file = f"{model_path}/model.bin"
if not os.path.isdir(model_path) or not os.path.isfile(model_bin_file):
model_path = model_size

logger.info(f"loading model: {model_path}, device: {device}, compute_type: {compute_type}")
model = WhisperModel(model_size_or_path=model_path,
device=device,
compute_type=compute_type)

Expand Down

0 comments on commit 1c7d7e1

Please sign in to comment.