futurespyhi commited on
Commit
8b5e5aa
·
1 Parent(s): 326af3b

Update lyrics with improved format recognition - extract only segments

Browse files
Files changed (2) hide show
  1. .gitignore +1 -0
  2. app.py +44 -6
.gitignore CHANGED
@@ -110,6 +110,7 @@ packages.txt.backup
110
  requirements.txt.backup
111
  download_model.py.backup
112
  decode_vocode.txt
 
113
 
114
  # test files
115
  tests/
 
110
  requirements.txt.backup
111
  download_model.py.backup
112
  decode_vocode.txt
113
+ backup/
114
 
115
  # test files
116
  tests/
app.py CHANGED
@@ -558,9 +558,9 @@ def respond(message, state):
558
  # Add assistant response
559
  state.conversation.append({"role": "assistant", "content": response})
560
 
561
- # Update lyrics with improved format recognition
562
  if any(marker in response.lower() for marker in ["[verse", "[chorus", "[bridge", "**verse", "**chorus", "sectiontype.verse", "verse:"]):
563
- state.lyrics = response
564
 
565
  # Format conversation for display
566
  return "", [{"role": msg["role"], "content": msg["content"]} for msg in state.conversation], state
@@ -866,9 +866,9 @@ def response_audio(state: AppState, audio: tuple, genre_value, mood_value, theme
866
 
867
  state.conversation.append({"role": "assistant", "content": assistant_message})
868
 
869
- # Update lyrics using same logic as text input for consistency
870
  if any(marker in assistant_message.lower() for marker in ["[verse", "[chorus", "[bridge", "**verse", "**chorus", "sectiontype.verse", "verse:"]):
871
- state.lyrics = assistant_message
872
 
873
  os.remove(file_name)
874
 
@@ -879,6 +879,44 @@ def response_audio(state: AppState, audio: tuple, genre_value, mood_value, theme
879
 
880
  return state, conversation_display, state.lyrics
881
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
882
  def extract_lyrics_from_conversation(conversation):
883
  """
884
  Extract lyrics from conversation history with cross-platform compatibility.
@@ -889,11 +927,11 @@ def extract_lyrics_from_conversation(conversation):
889
  content_lower = message["content"].lower()
890
  # 先尝试严格匹配(保持原逻辑)
891
  if "verse" in content_lower and "chorus" in content_lower:
892
- lyrics = message["content"]
893
  break
894
  # 如果没找到,再用宽泛匹配(兼容性备选)
895
  elif any(marker in content_lower for marker in ["[verse", "[chorus", "**verse", "**chorus"]):
896
- lyrics = message["content"]
897
  break
898
  return lyrics
899
 
 
558
  # Add assistant response
559
  state.conversation.append({"role": "assistant", "content": response})
560
 
561
+ # Update lyrics with improved format recognition - extract only segments
562
  if any(marker in response.lower() for marker in ["[verse", "[chorus", "[bridge", "**verse", "**chorus", "sectiontype.verse", "verse:"]):
563
+ state.lyrics = extract_lyrics_segments_only(response)
564
 
565
  # Format conversation for display
566
  return "", [{"role": msg["role"], "content": msg["content"]} for msg in state.conversation], state
 
866
 
867
  state.conversation.append({"role": "assistant", "content": assistant_message})
868
 
869
+ # Update lyrics using same logic as text input for consistency - extract only segments
870
  if any(marker in assistant_message.lower() for marker in ["[verse", "[chorus", "[bridge", "**verse", "**chorus", "sectiontype.verse", "verse:"]):
871
+ state.lyrics = extract_lyrics_segments_only(assistant_message)
872
 
873
  os.remove(file_name)
874
 
 
879
 
880
  return state, conversation_display, state.lyrics
881
 
882
+ def extract_lyrics_segments_only(content):
883
+ """
884
+ Extract only the lyrics segments (VERSE, CHORUS, etc.) from AI response,
885
+ removing any AI commentary or explanation text.
886
+ """
887
+ import re
888
+
889
+ if not content:
890
+ return ""
891
+
892
+ lines = content.split('\n')
893
+ lyrics_lines = []
894
+ in_lyrics_section = False
895
+
896
+ for line in lines:
897
+ line = line.strip()
898
+
899
+ # Check if this line is a section header (VERSE, CHORUS, etc.)
900
+ if re.match(r'^\*\*(VERSE|CHORUS|BRIDGE|OUTRO).*\*\*$', line) or re.match(r'^\[(VERSE|CHORUS|BRIDGE|OUTRO).*\]$', line):
901
+ in_lyrics_section = True
902
+ lyrics_lines.append(line)
903
+ continue
904
+
905
+ # If we're in a lyrics section
906
+ if in_lyrics_section:
907
+ # Stop if we hit AI commentary
908
+ if line and any(phrase in line.lower() for phrase in [
909
+ 'how do you like', 'would you like', 'let me know',
910
+ 'what do you think', 'any changes', 'take a look',
911
+ 'here are the lyrics', 'i\'ve created', 'feel free to'
912
+ ]):
913
+ break
914
+
915
+ # Add lyrics line (including empty lines for formatting)
916
+ lyrics_lines.append(line)
917
+
918
+ return '\n'.join(lyrics_lines).strip()
919
+
920
  def extract_lyrics_from_conversation(conversation):
921
  """
922
  Extract lyrics from conversation history with cross-platform compatibility.
 
927
  content_lower = message["content"].lower()
928
  # 先尝试严格匹配(保持原逻辑)
929
  if "verse" in content_lower and "chorus" in content_lower:
930
+ lyrics = extract_lyrics_segments_only(message["content"])
931
  break
932
  # 如果没找到,再用宽泛匹配(兼容性备选)
933
  elif any(marker in content_lower for marker in ["[verse", "[chorus", "**verse", "**chorus"]):
934
+ lyrics = extract_lyrics_segments_only(message["content"])
935
  break
936
  return lyrics
937