Skip to content

Commit

Permalink
Fixed bug when LLM not available
Browse files Browse the repository at this point in the history
  • Loading branch information
beveradb committed Jul 14, 2024
1 parent d0c2701 commit 1ddd450
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions lyrics_transcriber/transcriber.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 1ddd450

Please sign in to comment.