Skip to content

Commit

Permalink
Auto-download spacy model
Browse files Browse the repository at this point in the history
  • Loading branch information
beveradb committed Jan 26, 2025
1 parent d03771a commit f20b712
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
17 changes: 13 additions & 4 deletions lyrics_transcriber/correction/phrase_analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,19 @@ def __init__(self, logger: logging.Logger, language_code: str = "en_core_web_sm"
try:
self.nlp = spacy.load(language_code)
except OSError:
self.logger.error(f"Failed to load language model: {language_code}")
raise OSError(
f"Language model '{language_code}' not found. " f"Please install it with: python -m spacy download {language_code}"
)
self.logger.info(f"Language model {language_code} not found. Attempting to download...")
import subprocess

try:
subprocess.check_call(["python", "-m", "spacy", "download", language_code])
self.nlp = spacy.load(language_code)
self.logger.info(f"Successfully downloaded and loaded {language_code}")
except subprocess.CalledProcessError as e:
self.logger.error(f"Failed to download language model: {language_code}")
raise OSError(
f"Language model '{language_code}' could not be downloaded. "
f"Please install it manually with: python -m spacy download {language_code}"
) from e

def score_phrase(self, words: List[str], context: str) -> PhraseScore:
"""Score a phrase based on grammatical completeness and natural breaks.
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "lyrics-transcriber"
version = "0.32.2"
version = "0.32.3"
description = "Automatically create synchronised lyrics files in ASS and MidiCo LRC formats with word-level timestamps, using Whisper and lyrics from Genius and Spotify"
authors = ["Andrew Beveridge <[email protected]>"]
license = "MIT"
Expand Down

0 comments on commit f20b712

Please sign in to comment.