import random class IntensifierGenerator: def __init__(self, genre="default", use_synonyms=True, use_metaphors=True): self.genre = genre self.use_synonyms = use_synonyms self.use_metaphors = use_metaphors self.intensifier_pool = self._load_intensifiers() def _load_intensifiers(self): base_pool = { "default": { "synonyms": ["wild", "burning", "endless", "raw"], "metaphors": ["like a comet", "like thunder", "like wildfire"] }, "pop": { "synonyms": ["electric", "neon", "glossy", "magnetic"], "metaphors": ["like a spotlight", "like glitter", "like a dream"] }, "rap": { "synonyms": ["cold", "lit", "savage", "dope"], "metaphors": ["like a flex", "like a cipher", "like a drop"] }, "rock": { "synonyms": ["gritty", "loud", "reckless", "feral"], "metaphors": ["like a riot", "like a storm", "like a scream"] }, "folk": { "synonyms": ["rustic", "earthy", "timeless", "weathered"], "metaphors": ["like the mountains", "like the wind", "like an old tale"] }, "r&b": { "synonyms": ["smooth", "sultry", "silky", "deep"], "metaphors": ["like midnight", "like honey", "like a slow dance"] }, "country": { "synonyms": ["dusty", "honest", "heartfelt", "rugged"], "metaphors": ["like an open road", "like a sunset", "like a whiskey glass"] }, "indie": { "synonyms": ["quirky", "intimate", "ethereal", "raw"], "metaphors": ["like a polaroid", "like a whisper", "like faded jeans"] }, "dance": { "synonyms": ["pulsing", "euphoric", "vibrant", "electric"], "metaphors": ["like a neon sign", "like a heartbeat", "like the night"] } } return base_pool.get(self.genre.lower(), base_pool["default"]) def generate(self, base_line): """Add genre-specific intensifiers to a line""" # Don't modify section headers if base_line.strip().startswith("[") and base_line.strip().endswith("]"): return base_line # Don't modify very short lines or empty lines if not base_line.strip() or len(base_line.split()) < 3: return base_line # Only enhance some lines (not every line) if random.random() > 0.4: # 40% chance to enhance return base_line intensifiers = [] if self.use_synonyms and random.random() > 0.5: intensifiers.append(random.choice(self.intensifier_pool["synonyms"])) if self.use_metaphors and random.random() > 0.7: # Less frequent metaphors intensifiers.append(random.choice(self.intensifier_pool["metaphors"])) if not intensifiers: return base_line # Add the intensifier in a natural position words = base_line.split() if len(words) > 4: # Insert at a natural break point insert_pos = len(words) // 2 words.insert(insert_pos, random.choice(intensifiers)) return " ".join(words) else: # Add at the end for short lines return f"{base_line} {random.choice(intensifiers)}" class RhymeEnhancer: """Enhance rhyming in lyrics""" def __init__(self): self.rhyme_endings = { "pop": ["ight", "ay", "ove", "art", "ame"], "rock": ["own", "ire", "ead", "ight", "one"], "rap": ["ay", "ow", "ack", "op", "ame"], "folk": ["ay", "ight", "ome", "and", "ow"], "r&b": ["ove", "ight", "ay", "oul", "ime"], "country": ["oad", "eart", "ome", "ight", "ay"], "indie": ["ight", "own", "ay", "ime", "ow"], "dance": ["ight", "ay", "ove", "own", "ire"] } def get_rhyme_ending(self, genre): """Get a rhyme ending for the given genre""" genre = genre.lower() if genre in self.rhyme_endings: return random.choice(self.rhyme_endings[genre]) return random.choice(self.rhyme_endings["pop"]) # Default to pop def enhance_line(self, line, rhyme_ending): """Try to make a line end with the given rhyme""" if not line.strip() or line.strip().startswith("["): return line # Only enhance some lines if random.random() > 0.3: # 30% chance to enhance return line words = line.split() if len(words) < 3: return line # Try to find a word that could be replaced with a rhyming word last_word = words[-1].lower().rstrip(",.!?;:") # Simple rhyming word replacements rhyme_words = { "ight": ["night", "light", "bright", "sight", "right", "tight"], "ay": ["day", "way", "stay", "play", "away", "today"], "ove": ["love", "above", "dove", "shove", "glove"], "art": ["heart", "start", "part", "chart", "smart"], "ame": ["fame", "game", "name", "flame", "shame"], "own": ["down", "town", "crown", "brown", "frown"], "ire": ["fire", "desire", "wire", "higher", "inspire"], "ead": ["head", "instead", "spread", "dread", "thread"], "one": ["stone", "alone", "bone", "tone", "zone"], "ack": ["back", "track", "black", "stack", "attack"], "op": ["top", "stop", "drop", "shop", "pop"], "ome": ["home", "roam", "dome", "chrome", "foam"], "and": ["hand", "stand", "band", "land", "grand"], "ow": ["now", "how", "bow", "allow", "somehow"], "oul": ["soul", "control", "roll", "whole", "goal"], "ime": ["time", "crime", "prime", "sublime", "climb"], "oad": ["road", "load", "code", "mode", "showed"], "eart": ["heart", "start", "part", "chart", "smart"], } if rhyme_ending in rhyme_words: # Replace the last word with a rhyming word words[-1] = random.choice(rhyme_words[rhyme_ending]) return " ".join(words) return line def enhance_section(self, lines, genre): """Enhance rhyming in a section of lyrics""" if not lines: return lines # Choose a rhyme ending for this section rhyme_ending = self.get_rhyme_ending(genre) # Enhance every other line to create an ABAB or AABB pattern enhanced_lines = [] for i, line in enumerate(lines): if i % 2 == 1: # Every other line enhanced_lines.append(self.enhance_line(line, rhyme_ending)) else: enhanced_lines.append(line) return enhanced_lines class SongStructureEnhancer: """Enhance the structure of song lyrics""" def __init__(self, genre="pop"): self.genre = genre.lower() self.chorus_templates = self._load_chorus_templates() def _load_chorus_templates(self): """Load chorus templates by genre""" templates = { "pop": [ "Baby, {0}\nYeah, {0}", "{0}\nI can't get enough\n{0}\nIt's never too much", "Oh-oh-oh\n{0}\nYeah-yeah-yeah\n{0}", "{0}\nAgain and again\n{0}\nUntil the end" ], "rock": [ "{0}\nIt's burning inside\n{0}\nI won't be denied", "Yeah! {0}\nWoah! {0}", "{0}\nI'm breaking free\n{0}\nCan't you see", "{0}\nIt's do or die\n{0}\nReach for the sky" ], "rap": [ "{0}\nThat's right\n{0}\nAll night", "{0}\nYou know what I'm saying\n{0}\nNo delaying", "{0}\nFor real\n{0}\nThat's the deal", "{0}\nYeah\n{0}\nUh" ], "folk": [ "{0}\nThrough the years\n{0}\nDespite our fears", "{0}\nLike the river flows\n{0}\nEverybody knows", "{0}\nTime will tell\n{0}\nAll is well", "{0}\nDay by day\n{0}\nCome what may" ], "r&b": [ "Ooh baby, {0}\nYou know that {0}", "{0}\nSo smooth\n{0}\nIn the groove", "{0}\nAll night long\n{0}\nSo strong", "{0}\nYou and me\n{0}\nDestiny" ], "country": [ "{0}\nDown that old road\n{0}\nCarrying that load", "{0}\nIn my heart\n{0}\nRight from the start", "{0}\nDay by day\n{0}\nCome what may", "{0}\nTrue and blue\n{0}\nThrough and through" ], "indie": [ "{0}\nIn my mind\n{0}\nHard to find", "{0}\nLike a dream\n{0}\nNothing's as it seems", "{0}\nFading light\n{0}\nInto the night", "{0}\nWe'll see\n{0}\nJust let it be" ], "dance": [ "{0}\nFeel the beat\n{0}\nSweep you off your feet", "{0}\nAll night long\n{0}\nCan't go wrong", "{0}\nMove your body\n{0}\nEverybody", "{0}\nDon't stop now\n{0}\nShow me how" ] } return templates.get(self.genre, templates["pop"]) def create_chorus(self, verse_line): """Create a chorus based on a line from the verse""" if not verse_line or verse_line.startswith("["): return ["[Chorus]", "We're living in the moment", "Feeling so alive"] # Extract a short phrase from the verse line words = verse_line.split() if len(words) >= 4: phrase = " ".join(words[-3:]) else: phrase = verse_line # Apply a chorus template template = random.choice(self.chorus_templates) chorus_text = template.format(phrase) # Split into lines and add the chorus header chorus_lines = ["[Chorus]"] + chorus_text.split("\n") return chorus_lines def create_bridge(self): """Create a bridge section""" bridge_templates = [ ["[Bridge]", "And now I see", "Everything has changed", "Nothing stays the same"], ["[Bridge]", "Take me higher", "Set my soul on fire", "This is my desire"], ["[Bridge]", "Breaking through", "Starting something new", "I'm coming back to you"], ["[Bridge]", "In between", "Not what it seems", "Living in a dream"] ] return random.choice(bridge_templates) def enhance_structure(self, lyrics, add_bridge=True): """Enhance the structure of the lyrics""" if not lyrics: return lyrics lines = lyrics.split("\n") # Find verse and chorus sections verse_sections = [] chorus_section = None current_section = [] current_type = None for line in lines: if "[Verse" in line: # Save previous section if current_type == "verse" and current_section: verse_sections.append(current_section) elif current_type == "chorus" and current_section: chorus_section = current_section # Start new verse section current_section = [line] current_type = "verse" elif "[Chorus]" in line: # Save previous section if current_type == "verse" and current_section: verse_sections.append(current_section) # Start new chorus section current_section = [line] current_type = "chorus" else: current_section.append(line) # Save the last section if current_type == "verse" and current_section: verse_sections.append(current_section) elif current_type == "chorus" and current_section: chorus_section = current_section # If no chorus found, create one from the first verse if not chorus_section and verse_sections: verse_lines = verse_sections[0] # Find a good line to base the chorus on for line in verse_lines: if line and not line.startswith("[") and len(line.split()) >= 3: chorus_section = self.create_chorus(line) break if not chorus_section: chorus_section = ["[Chorus]", "We're living in the moment", "Feeling so alive"] # Rebuild the lyrics with proper structure structured_lines = [] # Add first verse if verse_sections: structured_lines.extend(verse_sections[0]) structured_lines.append("") # Empty line for spacing # Add chorus if chorus_section: structured_lines.extend(chorus_section) structured_lines.append("") # Empty line for spacing # Add second verse if available if len(verse_sections) > 1: structured_lines.extend(verse_sections[1]) structured_lines.append("") # Empty line for spacing # Repeat chorus if chorus_section: structured_lines.extend(chorus_section) structured_lines.append("") # Empty line for spacing # Add bridge if requested and we have enough content if add_bridge and len(structured_lines) > 10: bridge = self.create_bridge() structured_lines.extend(bridge) structured_lines.append("") # Empty line for spacing # Final chorus if chorus_section: structured_lines.extend(chorus_section) # If we only have one verse and no second verse, add the chorus again elif len(verse_sections) <= 1 and chorus_section: structured_lines.extend(chorus_section) return "\n".join(structured_lines)