root
commited on
Commit
Β·
19c0923
1
Parent(s):
14555be
css
Browse files
README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
---
|
| 2 |
-
title: Music
|
| 3 |
emoji: π΅
|
| 4 |
colorFrom: indigo
|
| 5 |
colorTo: purple
|
|
@@ -8,40 +8,109 @@ sdk_version: 5.22.0
|
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
license: mit
|
| 11 |
-
short_description: AI music
|
| 12 |
---
|
| 13 |
|
| 14 |
-
# Music
|
| 15 |
|
| 16 |
-
This
|
| 17 |
|
| 18 |
-
|
| 19 |
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
-
|
| 25 |
-
-
|
| 26 |
-
-
|
| 27 |
-
-
|
| 28 |
-
- Simple and intuitive user interface
|
| 29 |
|
| 30 |
-
##
|
| 31 |
|
| 32 |
-
1.
|
| 33 |
-
2.
|
| 34 |
-
3.
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
-
##
|
| 38 |
|
| 39 |
-
|
| 40 |
-
-
|
| 41 |
-
-
|
| 42 |
-
-
|
|
|
|
|
|
|
| 43 |
|
| 44 |
-
|
| 45 |
|
| 46 |
-
|
| 47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Advanced Music Analysis & Beat-Matched Lyrics Generator
|
| 3 |
emoji: π΅
|
| 4 |
colorFrom: indigo
|
| 5 |
colorTo: purple
|
|
|
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
license: mit
|
| 11 |
+
short_description: AI-powered music analysis with beat-synchronized lyrics generation
|
| 12 |
---
|
| 13 |
|
| 14 |
+
# Advanced Music Analysis & Beat-Matched Lyrics Generator
|
| 15 |
|
| 16 |
+
This comprehensive AI-powered application provides advanced music analysis and generates perfectly synchronized lyrics that match the musical structure, rhythm, and emotional content of your audio files.
|
| 17 |
|
| 18 |
+
## π― Key Features
|
| 19 |
|
| 20 |
+
### πΌ **Comprehensive Music Analysis**
|
| 21 |
+
- **Genre Classification**: Automatic detection using [dima806/music_genres_classification](https://huggingface.co/dima806/music_genres_classification)
|
| 22 |
+
- **Tempo & Time Signature Detection**: Advanced multi-method analysis (4/4, 3/4, 6/8)
|
| 23 |
+
- **Emotional Analysis**: 8-dimensional emotion detection (happy, sad, excited, calm, etc.)
|
| 24 |
+
- **Thematic Analysis**: Identifies musical themes (love, triumph, loss, adventure, etc.)
|
| 25 |
+
- **Tonal Analysis**: Key detection, mode analysis (major/minor), harmonic complexity
|
| 26 |
+
- **Beat Pattern Analysis**: Precise beat tracking and stress pattern identification
|
| 27 |
|
| 28 |
+
### π€ **Beat-Synchronized Lyrics Generation**
|
| 29 |
+
- **Rhythm-Matched Lyrics**: Each line perfectly aligns with musical phrases and beat patterns
|
| 30 |
+
- **Syllable-to-Beat Mapping**: Precise syllable counting and stress pattern matching
|
| 31 |
+
- **Custom Requirements Integration**: Add your own creative directions and themes
|
| 32 |
+
- **Genre-Specific Optimization**: Tailored for Pop, Rock, Country, Disco, and Metal
|
| 33 |
+
- **Flow Analysis**: Ensures natural sentence flow across multiple lines
|
| 34 |
+
- **Quality Metrics**: Detailed beat matching and syllable accuracy analysis
|
| 35 |
|
| 36 |
+
### π¨ **Personalization Features**
|
| 37 |
+
- **Custom Prompt Input**: Specify themes, imagery, perspective, style, or content requirements
|
| 38 |
+
- **Intelligent Blending**: Merges your requirements with detected musical characteristics
|
| 39 |
+
- **Flexible Creative Control**: From simple themes to complex narrative directions
|
|
|
|
| 40 |
|
| 41 |
+
## π How It Works
|
| 42 |
|
| 43 |
+
1. **Upload Audio**: Support for various audio formats, or record directly
|
| 44 |
+
2. **Add Custom Requirements** (Optional): Specify your creative vision
|
| 45 |
+
3. **Advanced Analysis**: Multi-layered analysis of musical characteristics:
|
| 46 |
+
- Rhythm and tempo analysis
|
| 47 |
+
- Time signature detection using autocorrelation, pattern matching, and spectral analysis
|
| 48 |
+
- Emotional profiling using valence-arousal mapping
|
| 49 |
+
- Thematic classification based on musical features
|
| 50 |
+
- Beat pattern extraction and stress analysis
|
| 51 |
+
4. **Lyrics Generation**: AI creates lyrics using [Qwen/QwQ-32B](https://huggingface.co/Qwen/QwQ-32B) that:
|
| 52 |
+
- Match the detected beat patterns and time signature
|
| 53 |
+
- Incorporate detected emotions and themes
|
| 54 |
+
- Follow your custom creative requirements
|
| 55 |
+
- Maintain proper syllable-to-beat ratios for the genre
|
| 56 |
+
5. **Quality Analysis**: Comprehensive beat matching analysis with accuracy metrics
|
| 57 |
|
| 58 |
+
## π΅ Supported Genres for Lyrics Generation
|
| 59 |
|
| 60 |
+
**Full Support** (Analysis + Beat-Matched Lyrics):
|
| 61 |
+
- **Pop**: Optimized syllable patterns and emotional expression
|
| 62 |
+
- **Rock**: Energetic phrasing with strong beat emphasis
|
| 63 |
+
- **Country**: Narrative flow with authentic storytelling patterns
|
| 64 |
+
- **Disco**: Rhythmic momentum with dance-friendly phrasing
|
| 65 |
+
- **Metal**: Intense expression with dramatic beat alignment
|
| 66 |
|
| 67 |
+
**Analysis Only**: All other genres receive comprehensive musical analysis without lyrics generation.
|
| 68 |
|
| 69 |
+
## π οΈ Technical Features
|
| 70 |
+
|
| 71 |
+
### Advanced Analysis Algorithms
|
| 72 |
+
- **Multi-Method Time Signature Detection**: Combines autocorrelation, pattern matching, spectral analysis, note density analysis, and tempo-based estimation
|
| 73 |
+
- **Emotion Mapping**: 8-dimensional emotion space with valence-arousal coordinates
|
| 74 |
+
- **Beat Strength Analysis**: Onset detection with energy and spectral flux analysis
|
| 75 |
+
- **Syllable Stress Matching**: CMU Dictionary integration with rule-based fallback
|
| 76 |
+
|
| 77 |
+
### AI-Powered Generation
|
| 78 |
+
- **4-bit Quantization**: Efficient inference on T4 GPU using BitsAndBytesConfig
|
| 79 |
+
- **Specialized Prompting**: Genre-aware prompt engineering for optimal results
|
| 80 |
+
- **Quality Enforcement**: Automatic syllable limit enforcement and line count validation
|
| 81 |
+
- **Flow Optimization**: Sentence continuation analysis for natural lyrical flow
|
| 82 |
+
|
| 83 |
+
## π Analysis Outputs
|
| 84 |
+
|
| 85 |
+
### Musical Analysis
|
| 86 |
+
- Tempo (BPM) and time signature with confidence scores
|
| 87 |
+
- Primary and secondary emotions with confidence percentages
|
| 88 |
+
- Musical themes and their relevance scores
|
| 89 |
+
- Key signature and mode detection
|
| 90 |
+
- Beat pattern visualization
|
| 91 |
+
|
| 92 |
+
### Lyrics Quality Metrics
|
| 93 |
+
- Syllable-to-beat match accuracy
|
| 94 |
+
- Stress pattern alignment scores
|
| 95 |
+
- Sentence flow quality assessment
|
| 96 |
+
- Genre-appropriate range compliance
|
| 97 |
+
- Overall rhythmic accuracy percentage
|
| 98 |
+
|
| 99 |
+
## π― Custom Requirements Examples
|
| 100 |
+
|
| 101 |
+
**Themes**: "Write about a journey through mountains", "Focus on urban nightlife"
|
| 102 |
+
**Imagery**: "Use ocean metaphors", "Include references to light and shadow"
|
| 103 |
+
**Perspective**: "From a child's viewpoint", "Nostalgic memories", "Future aspirations"
|
| 104 |
+
**Style**: "Conversational tone", "Include internal rhymes", "Simple everyday language"
|
| 105 |
+
**Content**: "Avoid melancholy", "Include words 'freedom' and 'horizon'", "Focus on resilience"
|
| 106 |
+
|
| 107 |
+
## π Model Credits
|
| 108 |
+
|
| 109 |
+
- **Genre Classification**: [dima806/music_genres_classification](https://huggingface.co/dima806/music_genres_classification)
|
| 110 |
+
- **Lyrics Generation**: [Qwen/QwQ-32B](https://huggingface.co/Qwen/QwQ-32B) with 4-bit quantization
|
| 111 |
+
- **Audio Processing**: librosa, scipy, numpy for advanced signal processing
|
| 112 |
+
- **Linguistic Analysis**: NLTK CMU Dictionary for syllable counting and stress analysis
|
| 113 |
+
|
| 114 |
+
## πͺ Try It Now
|
| 115 |
+
|
| 116 |
+
Experience the future of AI-powered music analysis and lyrics generation. Upload your music and watch as the system creates perfectly synchronized, emotionally resonant lyrics tailored to your creative vision!
|
app.py
CHANGED
|
@@ -87,7 +87,7 @@ except Exception as e:
|
|
| 87 |
music_analyzer = MusicAnalyzer()
|
| 88 |
|
| 89 |
# Process uploaded audio file
|
| 90 |
-
def process_audio(audio_file):
|
| 91 |
if audio_file is None:
|
| 92 |
return "No audio file provided", None, None, None, None, None, None, None, None, None
|
| 93 |
|
|
@@ -200,7 +200,7 @@ def process_audio(audio_file):
|
|
| 200 |
|
| 201 |
# Generate lyrics only for supported genres
|
| 202 |
if genre_supported:
|
| 203 |
-
lyrics = generate_lyrics(music_analysis, primary_genre, duration)
|
| 204 |
beat_match_analysis = analyze_lyrics_rhythm_match(lyrics, lyric_templates, primary_genre)
|
| 205 |
else:
|
| 206 |
supported_genres_str = ", ".join([genre.capitalize() for genre in beat_analyzer.supported_genres])
|
|
@@ -214,7 +214,7 @@ def process_audio(audio_file):
|
|
| 214 |
print(error_msg)
|
| 215 |
return error_msg, None, None, None, None, None, None, None, None, None
|
| 216 |
|
| 217 |
-
def generate_lyrics(music_analysis, genre, duration):
|
| 218 |
try:
|
| 219 |
# Extract meaningful information for context
|
| 220 |
tempo = music_analysis["rhythm_analysis"]["tempo"]
|
|
@@ -242,7 +242,8 @@ def generate_lyrics(music_analysis, genre, duration):
|
|
| 242 |
min_syl_for_prompt = 2
|
| 243 |
max_syl_for_prompt = 7
|
| 244 |
|
| 245 |
-
|
|
|
|
| 246 |
|
| 247 |
SONG DETAILS:
|
| 248 |
- Key: {key} {mode}
|
|
@@ -250,7 +251,18 @@ SONG DETAILS:
|
|
| 250 |
- Primary emotion: {primary_emotion}
|
| 251 |
- Secondary emotion: {secondary_emotion}
|
| 252 |
- Primary theme: {primary_theme}
|
| 253 |
-
- Secondary theme: {secondary_theme}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 254 |
|
| 255 |
CRITICAL REQUIREMENTS (MOST IMPORTANT):
|
| 256 |
- You MUST write EXACTLY {num_phrases_for_prompt} lines of lyrics.
|
|
@@ -288,14 +300,15 @@ Under the "LYRICS:" heading, provide exactly {num_phrases_for_prompt} numbered l
|
|
| 288 |
LYRICS:
|
| 289 |
(Your {num_phrases_for_prompt} numbered lyric lines go here, each starting with its number, a period, and a space)
|
| 290 |
|
| 291 |
-
Remember: Output EXACTLY {num_phrases_for_prompt} numbered lyric lines. Each line's content (after removing the number) must be {min_syl_for_prompt}-{max_syl_for_prompt} syllables.'''
|
| 292 |
else:
|
| 293 |
# Calculate the typical syllable range for this genre
|
| 294 |
num_phrases_for_prompt = len(lyric_templates)
|
| 295 |
max_syl_for_prompt = max([t.get('max_expected', 7) for t in lyric_templates]) if lyric_templates and lyric_templates[0].get('max_expected') else 7
|
| 296 |
min_syl_for_prompt = min([t.get('min_expected', 2) for t in lyric_templates]) if lyric_templates and lyric_templates[0].get('min_expected') else 2
|
| 297 |
|
| 298 |
-
|
|
|
|
| 299 |
|
| 300 |
SONG DETAILS:
|
| 301 |
- Key: {key} {mode}
|
|
@@ -303,7 +316,18 @@ SONG DETAILS:
|
|
| 303 |
- Primary emotion: {primary_emotion}
|
| 304 |
- Secondary emotion: {secondary_emotion}
|
| 305 |
- Primary theme: {primary_theme}
|
| 306 |
-
- Secondary theme: {secondary_theme}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 307 |
|
| 308 |
CRITICAL REQUIREMENTS (MOST IMPORTANT):
|
| 309 |
- You MUST write EXACTLY {num_phrases_for_prompt} lines of lyrics.
|
|
@@ -341,7 +365,7 @@ Under the "LYRICS:" heading, provide exactly {num_phrases_for_prompt} numbered l
|
|
| 341 |
LYRICS:
|
| 342 |
(Your {num_phrases_for_prompt} numbered lyric lines go here, each starting with its number, a period, and a space)
|
| 343 |
|
| 344 |
-
Remember: Output EXACTLY {num_phrases_for_prompt} numbered lyric lines. Each line's content (after removing the number) must be {min_syl_for_prompt}-{max_syl_for_prompt} syllables.'''
|
| 345 |
# Generate with optimized parameters for QwQ model
|
| 346 |
messages = [
|
| 347 |
{"role": "user", "content": prompt}
|
|
@@ -832,46 +856,55 @@ def enforce_syllable_limits(lines, max_syllables=6):
|
|
| 832 |
|
| 833 |
# Create Gradio interface
|
| 834 |
def create_interface():
|
| 835 |
-
with gr.Blocks(title="Music Analysis & Lyrics Generator") as demo:
|
| 836 |
-
gr.Markdown("# Music Analysis & Lyrics Generator")
|
| 837 |
-
gr.Markdown("Upload
|
| 838 |
|
| 839 |
with gr.Row():
|
| 840 |
with gr.Column(scale=1):
|
| 841 |
audio_input = gr.Audio(
|
| 842 |
-
label="Upload or Record Audio",
|
| 843 |
type="filepath",
|
| 844 |
sources=["upload", "microphone"]
|
| 845 |
)
|
| 846 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 847 |
|
| 848 |
with gr.Column(scale=2):
|
| 849 |
-
with gr.Tab("Analysis"):
|
| 850 |
-
analysis_output = gr.Textbox(label="Music Analysis Results", lines=10)
|
| 851 |
|
| 852 |
with gr.Row():
|
| 853 |
-
tempo_output = gr.Number(label="Tempo (BPM)")
|
| 854 |
-
time_sig_output = gr.Textbox(label="Time Signature")
|
| 855 |
|
| 856 |
with gr.Row():
|
| 857 |
-
primary_emotion_output = gr.Textbox(label="Primary Emotion")
|
| 858 |
-
secondary_emotion_output = gr.Textbox(label="Secondary Emotion")
|
| 859 |
|
| 860 |
with gr.Row():
|
| 861 |
-
primary_theme_output = gr.Textbox(label="Primary Theme")
|
| 862 |
-
secondary_theme_output = gr.Textbox(label="Secondary Theme")
|
| 863 |
-
genre_output = gr.Textbox(label="Primary Genre")
|
| 864 |
|
| 865 |
-
with gr.Tab("Generated Lyrics"):
|
| 866 |
-
lyrics_output = gr.Textbox(label="
|
| 867 |
|
| 868 |
-
with gr.Tab("Beat Matching"):
|
| 869 |
-
beat_match_output = gr.Markdown(label="
|
| 870 |
|
| 871 |
# Set up event handlers
|
| 872 |
analyze_btn.click(
|
| 873 |
fn=process_audio,
|
| 874 |
-
inputs=[audio_input],
|
| 875 |
outputs=[
|
| 876 |
analysis_output, lyrics_output, tempo_output, time_sig_output,
|
| 877 |
primary_emotion_output, secondary_emotion_output,
|
|
@@ -881,22 +914,57 @@ def create_interface():
|
|
| 881 |
)
|
| 882 |
|
| 883 |
# Format supported genres for display
|
| 884 |
-
supported_genres_md = "\n".join([f"- {genre.capitalize()}" for genre in beat_analyzer.supported_genres])
|
| 885 |
|
| 886 |
gr.Markdown(f"""
|
| 887 |
-
## How
|
| 888 |
-
|
| 889 |
-
|
| 890 |
-
|
| 891 |
-
|
| 892 |
-
|
| 893 |
-
|
| 894 |
-
|
| 895 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 896 |
{supported_genres_md}
|
| 897 |
|
| 898 |
-
These genres have consistent syllable-to-beat patterns that work
|
| 899 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 900 |
""")
|
| 901 |
|
| 902 |
return demo
|
|
|
|
| 87 |
music_analyzer = MusicAnalyzer()
|
| 88 |
|
| 89 |
# Process uploaded audio file
|
| 90 |
+
def process_audio(audio_file, custom_prompt=""):
|
| 91 |
if audio_file is None:
|
| 92 |
return "No audio file provided", None, None, None, None, None, None, None, None, None
|
| 93 |
|
|
|
|
| 200 |
|
| 201 |
# Generate lyrics only for supported genres
|
| 202 |
if genre_supported:
|
| 203 |
+
lyrics = generate_lyrics(music_analysis, primary_genre, duration, custom_prompt)
|
| 204 |
beat_match_analysis = analyze_lyrics_rhythm_match(lyrics, lyric_templates, primary_genre)
|
| 205 |
else:
|
| 206 |
supported_genres_str = ", ".join([genre.capitalize() for genre in beat_analyzer.supported_genres])
|
|
|
|
| 214 |
print(error_msg)
|
| 215 |
return error_msg, None, None, None, None, None, None, None, None, None
|
| 216 |
|
| 217 |
+
def generate_lyrics(music_analysis, genre, duration, custom_prompt=""):
|
| 218 |
try:
|
| 219 |
# Extract meaningful information for context
|
| 220 |
tempo = music_analysis["rhythm_analysis"]["tempo"]
|
|
|
|
| 242 |
min_syl_for_prompt = 2
|
| 243 |
max_syl_for_prompt = 7
|
| 244 |
|
| 245 |
+
# Build the base prompt
|
| 246 |
+
base_prompt = f'''You are a professional songwriter. Write song lyrics for a {genre} song.
|
| 247 |
|
| 248 |
SONG DETAILS:
|
| 249 |
- Key: {key} {mode}
|
|
|
|
| 251 |
- Primary emotion: {primary_emotion}
|
| 252 |
- Secondary emotion: {secondary_emotion}
|
| 253 |
- Primary theme: {primary_theme}
|
| 254 |
+
- Secondary theme: {secondary_theme}'''
|
| 255 |
+
|
| 256 |
+
# Add custom requirements if provided
|
| 257 |
+
custom_requirements = ""
|
| 258 |
+
if custom_prompt and custom_prompt.strip():
|
| 259 |
+
custom_requirements = f'''
|
| 260 |
+
|
| 261 |
+
SPECIAL REQUIREMENTS FROM USER:
|
| 262 |
+
{custom_prompt.strip()}
|
| 263 |
+
Please incorporate these requirements while still following all the technical constraints below.'''
|
| 264 |
+
|
| 265 |
+
prompt = base_prompt + custom_requirements + f'''
|
| 266 |
|
| 267 |
CRITICAL REQUIREMENTS (MOST IMPORTANT):
|
| 268 |
- You MUST write EXACTLY {num_phrases_for_prompt} lines of lyrics.
|
|
|
|
| 300 |
LYRICS:
|
| 301 |
(Your {num_phrases_for_prompt} numbered lyric lines go here, each starting with its number, a period, and a space)
|
| 302 |
|
| 303 |
+
Remember: Output EXACTLY {num_phrases_for_prompt} numbered lyric lines. Each line's content (after removing the number) must be {min_syl_for_prompt}-{max_syl_for_prompt} syllables.'''
|
| 304 |
else:
|
| 305 |
# Calculate the typical syllable range for this genre
|
| 306 |
num_phrases_for_prompt = len(lyric_templates)
|
| 307 |
max_syl_for_prompt = max([t.get('max_expected', 7) for t in lyric_templates]) if lyric_templates and lyric_templates[0].get('max_expected') else 7
|
| 308 |
min_syl_for_prompt = min([t.get('min_expected', 2) for t in lyric_templates]) if lyric_templates and lyric_templates[0].get('min_expected') else 2
|
| 309 |
|
| 310 |
+
# Build the base prompt
|
| 311 |
+
base_prompt = f'''You are a professional songwriter. Write song lyrics for a {genre} song.
|
| 312 |
|
| 313 |
SONG DETAILS:
|
| 314 |
- Key: {key} {mode}
|
|
|
|
| 316 |
- Primary emotion: {primary_emotion}
|
| 317 |
- Secondary emotion: {secondary_emotion}
|
| 318 |
- Primary theme: {primary_theme}
|
| 319 |
+
- Secondary theme: {secondary_theme}'''
|
| 320 |
+
|
| 321 |
+
# Add custom requirements if provided
|
| 322 |
+
custom_requirements = ""
|
| 323 |
+
if custom_prompt and custom_prompt.strip():
|
| 324 |
+
custom_requirements = f'''
|
| 325 |
+
|
| 326 |
+
SPECIAL REQUIREMENTS FROM USER:
|
| 327 |
+
{custom_prompt.strip()}
|
| 328 |
+
Please incorporate these requirements while still following all the technical constraints below.'''
|
| 329 |
+
|
| 330 |
+
prompt = base_prompt + custom_requirements + f'''
|
| 331 |
|
| 332 |
CRITICAL REQUIREMENTS (MOST IMPORTANT):
|
| 333 |
- You MUST write EXACTLY {num_phrases_for_prompt} lines of lyrics.
|
|
|
|
| 365 |
LYRICS:
|
| 366 |
(Your {num_phrases_for_prompt} numbered lyric lines go here, each starting with its number, a period, and a space)
|
| 367 |
|
| 368 |
+
Remember: Output EXACTLY {num_phrases_for_prompt} numbered lyric lines. Each line's content (after removing the number) must be {min_syl_for_prompt}-{max_syl_for_prompt} syllables.'''
|
| 369 |
# Generate with optimized parameters for QwQ model
|
| 370 |
messages = [
|
| 371 |
{"role": "user", "content": prompt}
|
|
|
|
| 856 |
|
| 857 |
# Create Gradio interface
|
| 858 |
def create_interface():
|
| 859 |
+
with gr.Blocks(title="Advanced Music Analysis & Beat-Matched Lyrics Generator") as demo:
|
| 860 |
+
gr.Markdown("# π΅ Advanced Music Analysis & Beat-Matched Lyrics Generator")
|
| 861 |
+
gr.Markdown("**Upload music to get comprehensive analysis and generate perfectly synchronized lyrics that match the rhythm, emotion, and structure of your audio**")
|
| 862 |
|
| 863 |
with gr.Row():
|
| 864 |
with gr.Column(scale=1):
|
| 865 |
audio_input = gr.Audio(
|
| 866 |
+
label="π§ Upload or Record Audio",
|
| 867 |
type="filepath",
|
| 868 |
sources=["upload", "microphone"]
|
| 869 |
)
|
| 870 |
+
|
| 871 |
+
# Add custom prompt input
|
| 872 |
+
custom_prompt_input = gr.Textbox(
|
| 873 |
+
label="π¨ Custom Lyrics Requirements (Optional)",
|
| 874 |
+
placeholder="e.g., 'Write about a rainy day in the city' or 'Include metaphors about flying' or 'Make it about overcoming challenges'",
|
| 875 |
+
lines=3,
|
| 876 |
+
info="Add any specific requirements, themes, or creative directions for the lyrics. This will be merged with the music analysis to create personalized lyrics."
|
| 877 |
+
)
|
| 878 |
+
|
| 879 |
+
analyze_btn = gr.Button("π Analyze Music & Generate Lyrics", variant="primary", size="lg")
|
| 880 |
|
| 881 |
with gr.Column(scale=2):
|
| 882 |
+
with gr.Tab("π Music Analysis"):
|
| 883 |
+
analysis_output = gr.Textbox(label="Comprehensive Music Analysis Results", lines=10)
|
| 884 |
|
| 885 |
with gr.Row():
|
| 886 |
+
tempo_output = gr.Number(label="π₯ Tempo (BPM)")
|
| 887 |
+
time_sig_output = gr.Textbox(label="β±οΈ Time Signature")
|
| 888 |
|
| 889 |
with gr.Row():
|
| 890 |
+
primary_emotion_output = gr.Textbox(label="π Primary Emotion")
|
| 891 |
+
secondary_emotion_output = gr.Textbox(label="π Secondary Emotion")
|
| 892 |
|
| 893 |
with gr.Row():
|
| 894 |
+
primary_theme_output = gr.Textbox(label="π Primary Theme")
|
| 895 |
+
secondary_theme_output = gr.Textbox(label="πͺ Secondary Theme")
|
| 896 |
+
genre_output = gr.Textbox(label="πΌ Primary Genre")
|
| 897 |
|
| 898 |
+
with gr.Tab("π€ Generated Lyrics"):
|
| 899 |
+
lyrics_output = gr.Textbox(label="Beat-Synchronized Lyrics", lines=20)
|
| 900 |
|
| 901 |
+
with gr.Tab("π― Beat Matching Analysis"):
|
| 902 |
+
beat_match_output = gr.Markdown(label="Rhythm & Syllable Synchronization Analysis")
|
| 903 |
|
| 904 |
# Set up event handlers
|
| 905 |
analyze_btn.click(
|
| 906 |
fn=process_audio,
|
| 907 |
+
inputs=[audio_input, custom_prompt_input],
|
| 908 |
outputs=[
|
| 909 |
analysis_output, lyrics_output, tempo_output, time_sig_output,
|
| 910 |
primary_emotion_output, secondary_emotion_output,
|
|
|
|
| 914 |
)
|
| 915 |
|
| 916 |
# Format supported genres for display
|
| 917 |
+
supported_genres_md = "\n".join([f"- **{genre.capitalize()}**: Optimized for {genre} music patterns" for genre in beat_analyzer.supported_genres])
|
| 918 |
|
| 919 |
gr.Markdown(f"""
|
| 920 |
+
## π How It Works
|
| 921 |
+
|
| 922 |
+
1. **π§ Upload Audio**: Support for various formats (MP3, WAV, etc.) or record directly in your browser
|
| 923 |
+
2. **π¨ Add Custom Requirements** (Optional): Specify your creative vision, themes, or style preferences
|
| 924 |
+
3. **π Advanced Analysis**: Multi-layered analysis including:
|
| 925 |
+
- **Tempo & Time Signature**: Advanced detection using multiple algorithms
|
| 926 |
+
- **Emotional Profiling**: 8-dimensional emotion mapping (happy, sad, excited, calm, etc.)
|
| 927 |
+
- **Thematic Analysis**: Musical themes (love, triumph, adventure, reflection, etc.)
|
| 928 |
+
- **Beat Pattern Extraction**: Precise rhythm and stress pattern identification
|
| 929 |
+
- **Genre Classification**: AI-powered genre detection with confidence scores
|
| 930 |
+
4. **π€ Lyrics Generation**: AI creates perfectly synchronized lyrics that:
|
| 931 |
+
- **Match Beat Patterns**: Each line aligns with musical phrases and rhythm
|
| 932 |
+
- **Follow Syllable Constraints**: Precise syllable-to-beat mapping for natural flow
|
| 933 |
+
- **Incorporate Emotions & Themes**: Blend detected musical characteristics
|
| 934 |
+
- **Include Your Requirements**: Merge your creative directions seamlessly
|
| 935 |
+
5. **π Quality Analysis**: Comprehensive metrics showing beat matching accuracy and flow quality
|
| 936 |
+
|
| 937 |
+
## π¨ Custom Requirements Examples
|
| 938 |
+
|
| 939 |
+
**π Themes**: "Write about nature and freedom", "Focus on urban nightlife", "Tell a story about friendship"
|
| 940 |
+
|
| 941 |
+
**πΌοΈ Imagery**: "Use ocean metaphors", "Include references to stars and sky", "Focus on light and shadow"
|
| 942 |
+
|
| 943 |
+
**ποΈ Perspective**: "From a child's viewpoint", "Make it nostalgic", "Focus on hope and resilience"
|
| 944 |
+
|
| 945 |
+
**βοΈ Style**: "Use simple everyday language", "Include some rhyming", "Make it conversational"
|
| 946 |
+
|
| 947 |
+
**π Content**: "Avoid sad themes", "Include words 'journey' and 'home'", "Focus on personal growth"
|
| 948 |
+
|
| 949 |
+
The system intelligently blends your requirements with detected musical characteristics to create personalized, rhythm-perfect lyrics.
|
| 950 |
+
|
| 951 |
+
## π΅ Supported Genres for Full Lyrics Generation
|
| 952 |
+
|
| 953 |
+
**β
Full Support** (Complete Analysis + Beat-Matched Lyrics):
|
| 954 |
{supported_genres_md}
|
| 955 |
|
| 956 |
+
These genres have consistent syllable-to-beat patterns that work optimally with our advanced rhythm-matching algorithm.
|
| 957 |
+
|
| 958 |
+
**π Analysis Only**: All other genres receive comprehensive musical analysis (tempo, emotion, themes, etc.) without lyrics generation.
|
| 959 |
+
|
| 960 |
+
## π οΈ Advanced Features
|
| 961 |
+
|
| 962 |
+
- **π― Beat Synchronization**: Syllable-perfect alignment with musical phrases
|
| 963 |
+
- **π§ Emotion Integration**: Lyrics reflect detected emotional characteristics
|
| 964 |
+
- **π Theme Incorporation**: Musical themes guide lyrical content
|
| 965 |
+
- **π Quality Metrics**: Detailed analysis of rhythm matching accuracy
|
| 966 |
+
- **π Flow Optimization**: Natural sentence continuation across lines
|
| 967 |
+
- **βοΈ Genre Optimization**: Tailored patterns for different musical styles
|
| 968 |
""")
|
| 969 |
|
| 970 |
return demo
|