From 1ddd450398085c04c2f3a6c1a57900a136f5402a Mon Sep 17 00:00:00 2001 From: Andrew Beveridge Date: Sat, 13 Jul 2024 21:39:20 -0400 Subject: [PATCH] Fixed bug when LLM not available --- lyrics_transcriber/transcriber.py | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/lyrics_transcriber/transcriber.py b/lyrics_transcriber/transcriber.py index 5ea5485..008ed2c 100644 --- a/lyrics_transcriber/transcriber.py +++ b/lyrics_transcriber/transcriber.py @@ -32,8 +32,8 @@ def __init__( log_formatter=None, transcription_model="medium", llm_model="gpt-4o", - llm_prompt_matching="lyrics_transcriber/llm_prompts/llm_prompt_lyrics_matching_andrew_handwritten_20231118.txt", - llm_prompt_correction="lyrics_transcriber/llm_prompts/llm_prompt_lyrics_correction_andrew_handwritten_20231118.txt", + llm_prompt_matching=None, + llm_prompt_correction=None, render_video=False, video_resolution="360p", video_background_image=None, @@ -68,9 +68,25 @@ def __init__( self.transcription_model = transcription_model self.llm_model = llm_model + + # Use package-relative paths for prompt files + if llm_prompt_matching is None: + llm_prompt_matching = os.path.join( + os.path.dirname(__file__), "llm_prompts", "llm_prompt_lyrics_matching_andrew_handwritten_20231118.txt" + ) + if llm_prompt_correction is None: + llm_prompt_correction = os.path.join( + os.path.dirname(__file__), "llm_prompts", "llm_prompt_lyrics_correction_andrew_handwritten_20231118.txt" + ) + self.llm_prompt_matching = llm_prompt_matching self.llm_prompt_correction = llm_prompt_correction + if not os.path.exists(self.llm_prompt_matching): + raise FileNotFoundError(f"LLM prompt file not found: {self.llm_prompt_matching}") + if not os.path.exists(self.llm_prompt_correction): + raise FileNotFoundError(f"LLM prompt file not found: {self.llm_prompt_correction}") + self.openai_client = None if self.openai_api_key: @@ -958,8 +974,11 @@ def get_cache_filepath(self, extension): return cache_filepath def get_song_slug(self): - artist_slug = slugify.slugify(self.artist, lowercase=False) - title_slug = slugify.slugify(self.title, lowercase=False) + if not self.artist and not self.title: + return "unknown_song_" + self.get_file_hash(self.audio_filepath) + + artist_slug = slugify.slugify(self.artist or "unknown_artist", lowercase=False) + title_slug = slugify.slugify(self.title or "unknown_title", lowercase=False) return artist_slug + "-" + title_slug def get_file_hash(self, filepath):