Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -16,12 +16,13 @@ except Exception as e:
|
|
| 16 |
def generate_lyrics(theme, genre, rhyme_scheme="AABB", max_length=150):
|
| 17 |
"""Generate song lyrics based on input parameters"""
|
| 18 |
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
[Verse]
|
| 24 |
-
"""
|
| 25 |
|
| 26 |
try:
|
| 27 |
# Increase temperature for more creativity and reduce repetition
|
|
@@ -43,7 +44,7 @@ Start with:
|
|
| 43 |
print(f"Error with primary generation: {e}")
|
| 44 |
|
| 45 |
# Try with a simpler prompt
|
| 46 |
-
simple_prompt = f"A {genre} song about {theme}:\n\n[Verse]\n"
|
| 47 |
|
| 48 |
try:
|
| 49 |
# Try with different parameters
|
|
@@ -71,7 +72,7 @@ Start with:
|
|
| 71 |
lines = lyrics.split("\n")
|
| 72 |
# Skip empty lines and prompt-related lines
|
| 73 |
content_lines = []
|
| 74 |
-
skip_keywords = ["Write a", "Start with:", "rhyme scheme", "using the"]
|
| 75 |
|
| 76 |
for line in lines:
|
| 77 |
# Skip empty lines and lines containing prompt keywords
|
|
@@ -92,14 +93,6 @@ Start with:
|
|
| 92 |
# If we have very few unique lines compared to total lines, it's repetitive
|
| 93 |
if len(lines) > 5 and len(unique_lines) < len(lines) / 2:
|
| 94 |
return "The model generated repetitive content. Please try again with a different theme or genre."
|
| 95 |
-
|
| 96 |
-
# Add [Chorus] section if it doesn't exist and the lyrics are long enough
|
| 97 |
-
if "[Chorus]" not in formatted_lyrics and len(formatted_lyrics.split()) > 20:
|
| 98 |
-
verse_lines = formatted_lyrics.split("\n")
|
| 99 |
-
# Insert a chorus after some verse lines
|
| 100 |
-
chorus_position = min(6, len(verse_lines))
|
| 101 |
-
verse_lines.insert(chorus_position, "\n[Chorus]")
|
| 102 |
-
formatted_lyrics = "\n".join(verse_lines)
|
| 103 |
|
| 104 |
return formatted_lyrics
|
| 105 |
|
|
|
|
| 16 |
def generate_lyrics(theme, genre, rhyme_scheme="AABB", max_length=150):
|
| 17 |
"""Generate song lyrics based on input parameters"""
|
| 18 |
|
| 19 |
+
# A more structured prompt to guide the model towards a lyrical format
|
| 20 |
+
prompt = f"""Task: Write lyrics for a {genre} song.
|
| 21 |
+
Theme: {theme}
|
| 22 |
+
Rhyme: {rhyme_scheme}
|
| 23 |
+
Style: Poetic, emotional, with verses and a chorus.
|
| 24 |
|
| 25 |
+
[Verse 1]"""
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
try:
|
| 28 |
# Increase temperature for more creativity and reduce repetition
|
|
|
|
| 44 |
print(f"Error with primary generation: {e}")
|
| 45 |
|
| 46 |
# Try with a simpler prompt
|
| 47 |
+
simple_prompt = f"A {genre} song about {theme}:\n\n[Verse 1]\n"
|
| 48 |
|
| 49 |
try:
|
| 50 |
# Try with different parameters
|
|
|
|
| 72 |
lines = lyrics.split("\n")
|
| 73 |
# Skip empty lines and prompt-related lines
|
| 74 |
content_lines = []
|
| 75 |
+
skip_keywords = ["Write a", "Start with:", "rhyme scheme", "using the", "Task:", "Theme:", "Rhyme:", "Style:", "Lyrics:"]
|
| 76 |
|
| 77 |
for line in lines:
|
| 78 |
# Skip empty lines and lines containing prompt keywords
|
|
|
|
| 93 |
# If we have very few unique lines compared to total lines, it's repetitive
|
| 94 |
if len(lines) > 5 and len(unique_lines) < len(lines) / 2:
|
| 95 |
return "The model generated repetitive content. Please try again with a different theme or genre."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
|
| 97 |
return formatted_lyrics
|
| 98 |
|