Spaces:
Sleeping
Sleeping
Upload 7 files
Browse files- README.md +11 -29
- app.py +28 -75
- gitignore +36 -0
- package-lock.json +6 -0
- requirements.txt +1 -1
README.md
CHANGED
|
@@ -1,42 +1,24 @@
|
|
| 1 |
-
#
|
| 2 |
|
| 3 |
-
This Hugging Face Space generates
|
| 4 |
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
-
|
| 8 |
-
- **Professional song structure**: Proper verse-chorus format with optional bridge sections
|
| 9 |
-
- **Enhanced rhyming**: Intelligent rhyme patterns that match your selected scheme
|
| 10 |
-
- **Musical phrasing**: Short, catchy lines optimized for singing
|
| 11 |
-
- **Emotional hooks**: Repetition and emphasis in the right places
|
| 12 |
|
| 13 |
## How to Use
|
| 14 |
|
| 15 |
1. Enter a theme or topic for your song
|
| 16 |
-
2. Select a music genre (
|
| 17 |
3. Choose a rhyme scheme (AABB or ABAB)
|
| 18 |
-
4. Adjust the maximum length as needed
|
| 19 |
5. Click "Generate Lyrics" and enjoy your AI-created song!
|
| 20 |
|
| 21 |
## Technical Details
|
| 22 |
|
| 23 |
-
- Built with Gradio
|
| 24 |
-
- Uses Hugging Face Transformers
|
| 25 |
-
- Enhanced with custom lyric processing modules:
|
| 26 |
-
- IntensifierGenerator: Adds genre-specific intensifiers and metaphors
|
| 27 |
-
- RhymeEnhancer: Improves rhyming patterns
|
| 28 |
-
- SongStructureEnhancer: Creates proper verse-chorus-bridge structure
|
| 29 |
- Optimized for free-tier Spaces
|
| 30 |
-
|
| 31 |
-
---
|
| 32 |
-
title: Harmonyaixlyricgenerator
|
| 33 |
-
emoji: 🌍
|
| 34 |
-
colorFrom: red
|
| 35 |
-
colorTo: pink
|
| 36 |
-
sdk: gradio
|
| 37 |
-
sdk_version: 5.44.1
|
| 38 |
-
app_file: app.py
|
| 39 |
-
pinned: false
|
| 40 |
-
license: mit
|
| 41 |
-
short_description: Lyric generator
|
| 42 |
-
---
|
|
|
|
| 1 |
+
# AI Song Lyric Generator
|
| 2 |
|
| 3 |
+
This Hugging Face Space generates song lyrics using AI. It allows you to specify:
|
| 4 |
|
| 5 |
+
- Theme or topic
|
| 6 |
+
- Music genre
|
| 7 |
+
- Rhyme scheme
|
| 8 |
+
- Maximum length
|
| 9 |
|
| 10 |
+
The app uses a lightweight model (DistilGPT-2) optimized for Hugging Face Spaces.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
## How to Use
|
| 13 |
|
| 14 |
1. Enter a theme or topic for your song
|
| 15 |
+
2. Select a music genre (pop, rock, folk, or rap)
|
| 16 |
3. Choose a rhyme scheme (AABB or ABAB)
|
| 17 |
+
4. Adjust the maximum length as needed
|
| 18 |
5. Click "Generate Lyrics" and enjoy your AI-created song!
|
| 19 |
|
| 20 |
## Technical Details
|
| 21 |
|
| 22 |
+
- Built with Gradio 4.19.0
|
| 23 |
+
- Uses Hugging Face Transformers
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
- Optimized for free-tier Spaces
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.py
CHANGED
|
@@ -1,7 +1,5 @@
|
|
| 1 |
from transformers import pipeline
|
| 2 |
import gradio as gr
|
| 3 |
-
import random
|
| 4 |
-
from lyric_enhancer import IntensifierGenerator, RhymeEnhancer, SongStructureEnhancer
|
| 5 |
|
| 6 |
# Initialize models suitable for free tier
|
| 7 |
try:
|
|
@@ -18,16 +16,11 @@ except Exception as e:
|
|
| 18 |
def generate_lyrics(theme, genre, rhyme_scheme="AABB", max_length=150):
|
| 19 |
"""Generate song lyrics based on input parameters"""
|
| 20 |
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
structure_enhancer = SongStructureEnhancer(genre=genre)
|
| 25 |
-
|
| 26 |
-
# Build a more musical prompt
|
| 27 |
-
prompt = f"""Write a catchy {genre} song about {theme} with {rhyme_scheme} rhyme pattern.
|
| 28 |
-
Keep lines short and musical. Include emotional hooks and repetition.
|
| 29 |
|
| 30 |
-
[Verse
|
| 31 |
"""
|
| 32 |
|
| 33 |
try:
|
|
@@ -43,14 +36,14 @@ Keep lines short and musical. Include emotional hooks and repetition.
|
|
| 43 |
lyrics = result[0]['generated_text']
|
| 44 |
|
| 45 |
# Check if we got repetitive content
|
| 46 |
-
if lyrics.count("[Verse]") > 3 or lyrics.count("
|
| 47 |
raise ValueError("Repetitive output detected")
|
| 48 |
|
| 49 |
except Exception as e:
|
| 50 |
print(f"Error with primary generation: {e}")
|
| 51 |
|
| 52 |
# Try with a simpler prompt
|
| 53 |
-
simple_prompt = f"{genre} song
|
| 54 |
|
| 55 |
try:
|
| 56 |
# Try with different parameters
|
|
@@ -67,18 +60,18 @@ Keep lines short and musical. Include emotional hooks and repetition.
|
|
| 67 |
return f"Sorry, I couldn't generate lyrics at this time. Please try again with a different theme or genre."
|
| 68 |
|
| 69 |
# Better handling of output formatting
|
| 70 |
-
# Find the first occurrence of [Verse]
|
| 71 |
-
verse_index =
|
| 72 |
|
| 73 |
if verse_index != -1:
|
| 74 |
# Keep everything from [Verse] onwards
|
| 75 |
formatted_lyrics = lyrics[verse_index:].strip()
|
| 76 |
else:
|
| 77 |
-
# If
|
| 78 |
lines = lyrics.split("\n")
|
| 79 |
# Skip empty lines and prompt-related lines
|
| 80 |
content_lines = []
|
| 81 |
-
skip_keywords = ["Write", "
|
| 82 |
|
| 83 |
for line in lines:
|
| 84 |
# Skip empty lines and lines containing prompt keywords
|
|
@@ -99,43 +92,14 @@ Keep lines short and musical. Include emotional hooks and repetition.
|
|
| 99 |
# If we have very few unique lines compared to total lines, it's repetitive
|
| 100 |
if len(lines) > 5 and len(unique_lines) < len(lines) / 2:
|
| 101 |
return "The model generated repetitive content. Please try again with a different theme or genre."
|
| 102 |
-
|
| 103 |
-
# Apply our enhancers to make the lyrics more musical
|
| 104 |
-
|
| 105 |
-
# 1. First, enhance the structure
|
| 106 |
-
enhanced_lyrics = structure_enhancer.enhance_structure(formatted_lyrics, add_bridge=(max_length > 150))
|
| 107 |
-
|
| 108 |
-
# 2. Apply line-by-line enhancements
|
| 109 |
-
enhanced_lines = []
|
| 110 |
-
current_section = None
|
| 111 |
-
section_lines = []
|
| 112 |
-
|
| 113 |
-
for line in enhanced_lyrics.split("\n"):
|
| 114 |
-
# Track sections for rhyming purposes
|
| 115 |
-
if line.startswith("["):
|
| 116 |
-
# Process previous section
|
| 117 |
-
if section_lines and current_section:
|
| 118 |
-
# Apply rhyme enhancement to the section
|
| 119 |
-
rhymed_lines = rhymer.enhance_section(section_lines, genre)
|
| 120 |
-
enhanced_lines.extend(rhymed_lines)
|
| 121 |
-
section_lines = []
|
| 122 |
-
|
| 123 |
-
# Start new section
|
| 124 |
-
enhanced_lines.append(line)
|
| 125 |
-
current_section = line
|
| 126 |
-
continue
|
| 127 |
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
enhanced_lines.extend(rhymed_lines)
|
| 136 |
-
|
| 137 |
-
# Final enhanced lyrics
|
| 138 |
-
formatted_lyrics = "\n".join(enhanced_lines)
|
| 139 |
|
| 140 |
return formatted_lyrics
|
| 141 |
|
|
@@ -169,21 +133,17 @@ css = """
|
|
| 169 |
|
| 170 |
# Example themes for the interface
|
| 171 |
examples = [
|
| 172 |
-
["
|
| 173 |
-
["
|
| 174 |
-
["
|
| 175 |
-
["
|
| 176 |
-
["city lights and late nights", "rap", "ABAB", 200],
|
| 177 |
-
["lost love and redemption", "country", "AABB", 180],
|
| 178 |
-
["finding yourself", "indie", "ABAB", 170],
|
| 179 |
-
["midnight feelings", "r&b", "AABB", 160],
|
| 180 |
]
|
| 181 |
|
| 182 |
# Create Gradio interface with a custom theme
|
| 183 |
with gr.Blocks(css=css, theme="soft") as demo:
|
| 184 |
with gr.Column(elem_classes="container"):
|
| 185 |
-
gr.Markdown("# 🎵
|
| 186 |
-
gr.Markdown("Create
|
| 187 |
|
| 188 |
with gr.Row():
|
| 189 |
with gr.Column():
|
|
@@ -193,10 +153,10 @@ with gr.Blocks(css=css, theme="soft") as demo:
|
|
| 193 |
info="What should your song be about?"
|
| 194 |
)
|
| 195 |
genre_input = gr.Dropdown(
|
| 196 |
-
["pop", "rock", "folk", "rap"
|
| 197 |
label="Music Genre",
|
| 198 |
value="pop",
|
| 199 |
-
info="Select the musical style
|
| 200 |
)
|
| 201 |
rhyme_input = gr.Dropdown(
|
| 202 |
["AABB", "ABAB"],
|
|
@@ -230,21 +190,14 @@ with gr.Blocks(css=css, theme="soft") as demo:
|
|
| 230 |
"""
|
| 231 |
### How to use
|
| 232 |
1. Enter a theme or topic for your song
|
| 233 |
-
2. Select a music genre
|
| 234 |
3. Choose a rhyme scheme
|
| 235 |
-
4. Adjust the length as needed
|
| 236 |
5. Click "Generate Lyrics" and enjoy your AI-created song!
|
| 237 |
|
| 238 |
-
### Features
|
| 239 |
-
- Genre-specific intensifiers and metaphors
|
| 240 |
-
- Enhanced rhyming patterns
|
| 241 |
-
- Proper song structure with verse-chorus format
|
| 242 |
-
- Bridge sections in longer songs
|
| 243 |
-
- Catchy, singable lines optimized for each genre
|
| 244 |
-
|
| 245 |
---
|
| 246 |
|
| 247 |
-
*Note: This app uses a lightweight AI model (DistilGPT-2)
|
| 248 |
""",
|
| 249 |
elem_classes="footer"
|
| 250 |
)
|
|
|
|
| 1 |
from transformers import pipeline
|
| 2 |
import gradio as gr
|
|
|
|
|
|
|
| 3 |
|
| 4 |
# Initialize models suitable for free tier
|
| 5 |
try:
|
|
|
|
| 16 |
def generate_lyrics(theme, genre, rhyme_scheme="AABB", max_length=150):
|
| 17 |
"""Generate song lyrics based on input parameters"""
|
| 18 |
|
| 19 |
+
prompt = f"""Write a short {genre} song about {theme} with {rhyme_scheme} rhyme scheme.
|
| 20 |
+
|
| 21 |
+
Start with:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
+
[Verse]
|
| 24 |
"""
|
| 25 |
|
| 26 |
try:
|
|
|
|
| 36 |
lyrics = result[0]['generated_text']
|
| 37 |
|
| 38 |
# Check if we got repetitive content
|
| 39 |
+
if lyrics.count("[Verse]") > 3 or lyrics.count("Start with:") > 1:
|
| 40 |
raise ValueError("Repetitive output detected")
|
| 41 |
|
| 42 |
except Exception as e:
|
| 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
|
|
|
|
| 60 |
return f"Sorry, I couldn't generate lyrics at this time. Please try again with a different theme or genre."
|
| 61 |
|
| 62 |
# Better handling of output formatting
|
| 63 |
+
# Find the first occurrence of [Verse] and keep everything after it
|
| 64 |
+
verse_index = lyrics.find("[Verse]")
|
| 65 |
|
| 66 |
if verse_index != -1:
|
| 67 |
# Keep everything from [Verse] onwards
|
| 68 |
formatted_lyrics = lyrics[verse_index:].strip()
|
| 69 |
else:
|
| 70 |
+
# If [Verse] not found, try to find the actual content
|
| 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 |
# 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 |
|
|
|
|
| 133 |
|
| 134 |
# Example themes for the interface
|
| 135 |
examples = [
|
| 136 |
+
["lost in the forest", "folk", "AABB", 150],
|
| 137 |
+
["falling in love", "pop", "ABAB", 150],
|
| 138 |
+
["overcoming challenges", "rock", "AABB", 180],
|
| 139 |
+
["city life", "rap", "ABAB", 200],
|
|
|
|
|
|
|
|
|
|
|
|
|
| 140 |
]
|
| 141 |
|
| 142 |
# Create Gradio interface with a custom theme
|
| 143 |
with gr.Blocks(css=css, theme="soft") as demo:
|
| 144 |
with gr.Column(elem_classes="container"):
|
| 145 |
+
gr.Markdown("# 🎵 AI Song Lyric Generator", elem_classes="title")
|
| 146 |
+
gr.Markdown("Create unique song lyrics with AI assistance", elem_classes="subtitle")
|
| 147 |
|
| 148 |
with gr.Row():
|
| 149 |
with gr.Column():
|
|
|
|
| 153 |
info="What should your song be about?"
|
| 154 |
)
|
| 155 |
genre_input = gr.Dropdown(
|
| 156 |
+
["pop", "rock", "folk", "rap"],
|
| 157 |
label="Music Genre",
|
| 158 |
value="pop",
|
| 159 |
+
info="Select the musical style"
|
| 160 |
)
|
| 161 |
rhyme_input = gr.Dropdown(
|
| 162 |
["AABB", "ABAB"],
|
|
|
|
| 190 |
"""
|
| 191 |
### How to use
|
| 192 |
1. Enter a theme or topic for your song
|
| 193 |
+
2. Select a music genre
|
| 194 |
3. Choose a rhyme scheme
|
| 195 |
+
4. Adjust the length as needed
|
| 196 |
5. Click "Generate Lyrics" and enjoy your AI-created song!
|
| 197 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 198 |
---
|
| 199 |
|
| 200 |
+
*Note: This app uses a lightweight AI model (DistilGPT-2) optimized for Hugging Face Spaces.*
|
| 201 |
""",
|
| 202 |
elem_classes="footer"
|
| 203 |
)
|
gitignore
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Python
|
| 2 |
+
__pycache__/
|
| 3 |
+
*.py[cod]
|
| 4 |
+
*$py.class
|
| 5 |
+
*.so
|
| 6 |
+
.Python
|
| 7 |
+
env/
|
| 8 |
+
build/
|
| 9 |
+
develop-eggs/
|
| 10 |
+
dist/
|
| 11 |
+
downloads/
|
| 12 |
+
eggs/
|
| 13 |
+
.eggs/
|
| 14 |
+
lib/
|
| 15 |
+
lib64/
|
| 16 |
+
parts/
|
| 17 |
+
sdist/
|
| 18 |
+
var/
|
| 19 |
+
*.egg-info/
|
| 20 |
+
.installed.cfg
|
| 21 |
+
*.egg
|
| 22 |
+
|
| 23 |
+
# Virtual Environment
|
| 24 |
+
venv/
|
| 25 |
+
ENV/
|
| 26 |
+
.env
|
| 27 |
+
|
| 28 |
+
# IDE files
|
| 29 |
+
.idea/
|
| 30 |
+
.vscode/
|
| 31 |
+
*.swp
|
| 32 |
+
*.swo
|
| 33 |
+
|
| 34 |
+
# OS specific
|
| 35 |
+
.DS_Store
|
| 36 |
+
Thumbs.db
|
package-lock.json
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "harmonyaixlyricgenerator",
|
| 3 |
+
"lockfileVersion": 3,
|
| 4 |
+
"requires": true,
|
| 5 |
+
"packages": {}
|
| 6 |
+
}
|
requirements.txt
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
transformers>=4.30.0
|
| 2 |
-
gradio
|
| 3 |
torch>=2.0.0
|
| 4 |
accelerate>=0.20.0
|
|
|
|
| 1 |
transformers>=4.30.0
|
| 2 |
+
gradio>=4.19.0
|
| 3 |
torch>=2.0.0
|
| 4 |
accelerate>=0.20.0
|