Spaces:
Running
Running
futurespyhi
commited on
Commit
·
51c37c6
1
Parent(s):
2ce587d
modify conversation lyrics extraction for compatibility
Browse files
app.py
CHANGED
|
@@ -862,13 +862,20 @@ def response_audio(state: AppState, audio: tuple, genre_value, mood_value, theme
|
|
| 862 |
|
| 863 |
def extract_lyrics_from_conversation(conversation):
|
| 864 |
"""
|
| 865 |
-
Extract lyrics from conversation history.
|
| 866 |
"""
|
| 867 |
lyrics = ""
|
| 868 |
for message in reversed(conversation):
|
| 869 |
-
if message["role"] == "assistant"
|
| 870 |
-
|
| 871 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 872 |
return lyrics
|
| 873 |
|
| 874 |
def generate_chat_completion(client, history, genre, mood, theme):
|
|
|
|
| 862 |
|
| 863 |
def extract_lyrics_from_conversation(conversation):
|
| 864 |
"""
|
| 865 |
+
Extract lyrics from conversation history with cross-platform compatibility.
|
| 866 |
"""
|
| 867 |
lyrics = ""
|
| 868 |
for message in reversed(conversation):
|
| 869 |
+
if message["role"] == "assistant":
|
| 870 |
+
content_lower = message["content"].lower()
|
| 871 |
+
# 先尝试严格匹配(保持原逻辑)
|
| 872 |
+
if "verse" in content_lower and "chorus" in content_lower:
|
| 873 |
+
lyrics = message["content"]
|
| 874 |
+
break
|
| 875 |
+
# 如果没找到,再用宽泛匹配(兼容性备选)
|
| 876 |
+
elif any(marker in content_lower for marker in ["[verse", "[chorus", "**verse", "**chorus"]):
|
| 877 |
+
lyrics = message["content"]
|
| 878 |
+
break
|
| 879 |
return lyrics
|
| 880 |
|
| 881 |
def generate_chat_completion(client, history, genre, mood, theme):
|