File size: 14,378 Bytes
7fcd65f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Song Generator</title>
    <script src="https://cdn.jsdelivr.net/npm/react@18.0.0/umd/react.development.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/react-dom@18.0.0/umd/react-dom.development.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/@babel/standalone/babel.js"></script>
    <script src="https://cdn.tailwindcss.com"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css"></link>
    <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap" rel="stylesheet">
    <style>
        body {
            font-family: 'Poppins', sans-serif;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
        }
        .glass-morphism {
            background: rgba(255, 255, 255, 0.1);
            backdrop-filter: blur(10px);
            border: 1px solid rgba(255, 255, 255, 0.2);
        }
        .song-line {
            animation: fadeIn 0.5s ease-in-out;
        }
        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(10px); }
            to { opacity: 1; transform: translateY(0); }
        }
        .typing-animation {
            overflow: hidden;
            border-right: 3px solid;
            white-space: nowrap;
            animation: typing 3.5s steps(40, end), blink-caret 0.75s step-end infinite;
        }
        @keyframes typing {
            from { width: 0 }
            to { width: 100% }
        }
        @keyframes blink-caret {
            from, to { border-color: transparent }
            50% { border-color: white; }
        }
    </style>
</head>
<body>
    <div id="root"></div>

    <script type="text/babel">
        const { useState, useEffect } = React;

        const SongGenerator = () => {
            const [prompt, setPrompt] = useState('');
            const [generatedSong, setGeneratedSong] = useState(null);
            const [isGenerating, setIsGenerating] = useState(false);
            const [showSuccess, setShowSuccess] = useState(false);

            const generateSong = () => {
                if (!prompt.trim()) return;
                
                setIsGenerating(true);
                setShowSuccess(false);
                
                // Simulate API call
                setTimeout(() => {
                    const song = generateMockSong(prompt);
                    setGeneratedSong(song);
                    setIsGenerating(false);
                    setShowSuccess(true);
                }, 2000);
            };

            const generateMockSong = (prompt) => {
                const themes = ['love', 'freedom', 'nature', 'dreams', 'adventure', 'memories'];
                const moods = ['happy', 'sad', 'energetic', 'calm', 'reflective'];
                const structures = [
                    ['Verse 1', 'Pre-Chorus', 'Chorus', 'Verse 2', 'Chorus', 'Bridge', 'Chorus', 'Outro'],
                    ['Intro', 'Verse', 'Chorus', 'Verse', 'Chorus', 'Bridge', 'Chorus', 'Outro'],
                    ['Verse', 'Chorus', 'Verse', 'Chorus', 'Bridge', 'Chorus', 'Outro']
                ];
                
                const structure = structures[Math.floor(Math.random() * structures.length)];
                const theme = themes[Math.floor(Math.random() * themes.length)];
                const mood = moods[Math.floor(Math.random() * moods.length)];
                
                const lines = [];
                structure.forEach(section => {
                    lines.push(`[${section}]`);
                    for (let i = 0; i < 4; i++) {
                        const line = generateLine(prompt, theme, mood);
                        lines.push(line);
                    }
                });
                
                return {
                    title: `Song: ${prompt.charAt(0).toUpperCase() + prompt.slice(1)}`,
                    artist: 'AI Composer',
                    theme,
                    mood,
                    structure,
                    lyrics: lines
                };
            };

            const generateLine = (prompt, theme, mood) => {
                const words = {
                    love: ['heart', 'soul', 'kiss', 'embrace', 'forever', 'together', 'passion', 'romance'],
                    freedom: ['sky', 'fly', 'open', 'wings', 'break', 'free', 'wild', 'unbound'],
                    nature: ['sun', 'moon', 'stars', 'river', 'mountain', 'forest', 'ocean', 'breeze'],
                    dreams: ['night', 'sleep', 'wonder', 'magic', 'vision', 'future', 'hope', 'imagination'],
                    adventure: ['journey', 'explore', 'discover', 'path', 'road', 'destination', 'expedition', 'quest'],
                    memories: ['past', 'time', 'remember', 'yesterday', 'childhood', 'nostalgia', 'moments', 'stories']
                };
                
                const moodWords = {
                    happy: ['bright', 'smile', 'joy', 'laugh', 'dance', 'sing', 'cheer', 'glee'],
                    sad: ['tears', 'cry', 'pain', 'lost', 'alone', 'dark', 'shadow', 'grief'],
                    energetic: ['run', 'jump', 'power', 'strong', 'fast', 'rush', 'drive', 'force'],
                    calm: ['peace', 'quiet', 'still', 'serene', 'tranquil', 'soft', 'gentle', 'slow'],
                    reflective: ['think', 'wonder', 'question', 'search', 'find', 'understand', 'realize', 'contemplate']
                };
                
                const themeWords = words[theme] || words.love;
                const moodWord = moodWords[mood] || moodWords.happy;
                
                const lineWords = [];
                for (let i = 0; i < 5; i++) {
                    const word = Math.random() > 0.5 ? 
                        themeWords[Math.floor(Math.random() * themeWords.length)] : 
                        moodWord[Math.floor(Math.random() * moodWord.length)];
                    lineWords.push(word);
                }
                
                return lineWords.join(' ');
            };

            const copyToClipboard = () => {
                const text = generatedSong.lyrics.join('
');
                navigator.clipboard.writeText(text);
                alert('Song lyrics copied to clipboard!');
            };

            const downloadSong = () => {
                const text = generatedSong.lyrics.join('
');
                const blob = new Blob([text], { type: 'text/plain' });
                const url = window.URL.createObjectURL(blob);
                const a = document.createElement('a');
                a.href = url;
                a.download = `${generatedSong.title}.txt`;
                document.body.appendChild(a);
                a.click();
                document.body.removeChild(a);
                window.URL.revokeObjectURL(url);
            };

            return (
                <div className="min-h-screen p-4">
                    <header className="text-center py-6">
                        <a href="https://huggingface.co/spaces/akhaliq/anycoder" className="text-white text-xl font-semibold hover:underline">
                            Built with anycoder
                        </a>
                    </header>
                    
                    <main className="max-w-4xl mx-auto">
                        <div className="glass-morphism rounded-2xl p-8 shadow-2xl">
                            <h1 className="text-4xl font-bold text-white text-center mb-8">
                                <i className="fas fa-music mr-3"></i>
                                AI Song Generator
                            </h1>
                            
                            <div className="mb-6">
                                <label className="block text-white text-sm font-medium mb-2">
                                    Enter your song prompt:
                                </label>
                                <div className="flex gap-3">
                                    <input
                                        type="text"
                                        value={prompt}
                                        onChange={(e) => setPrompt(e.target.value)}
                                        placeholder="e.g., love story in Paris, summer adventure, lost memories"
                                        className="flex-1 px-4 py-3 rounded-lg bg-white bg-opacity-20 text-white placeholder-gray-300 border border-white border-opacity-30 focus:outline-none focus:ring-2 focus:ring-white focus:ring-opacity-50"
                                    />
                                    <button
                                        onClick={generateSong}
                                        disabled={isGenerating || !prompt.trim()}
                                        className="px-6 py-3 bg-white text-purple-600 font-semibold rounded-lg hover:bg-opacity-90 transition-all duration-300 disabled:opacity-50 disabled:cursor-not-allowed"
                                    >
                                        {isGenerating ? (
                                            <span className="flex items-center">
                                                <i className="fas fa-spinner fa-spin mr-2"></i>
                                                Generating...
                                            </span>
                                        ) : (
                                            <span className="flex items-center">
                                                <i className="fas fa-magic mr-2"></i>
                                                Generate
                                            </span>
                                        )}
                                    </button>
                                </div>
                            </div>
                            
                            {showSuccess && (
                                <div className="mb-6 p-4 bg-green-500 bg-opacity-20 border border-green-400 rounded-lg text-green-100">
                                    <i className="fas fa-check-circle mr-2"></i>
                                    Song generated successfully!
                                </div>
                            )}
                            
                            {generatedSong && (
                                <div className="bg-white bg-opacity-10 rounded-lg p-6">
                                    <div className="flex justify-between items-start mb-4">
                                        <div>
                                            <h2 className="text-2xl font-bold text-white">{generatedSong.title}</h2>
                                            <p className="text-gray-300">by {generatedSong.artist}</p>
                                            <div className="flex gap-4 mt-2">
                                                <span className="text-sm text-gray-300">
                                                    <i className="fas fa-tag mr-1"></i>
                                                    Theme: {generatedSong.theme}
                                                </span>
                                                <span className="text-sm text-gray-300">
                                                    <i className="fas fa-heart mr-1"></i>
                                                    Mood: {generatedSong.mood}
                                                </span>
                                            </div>
                                        </div>
                                        <div className="flex gap-2">
                                            <button
                                                onClick={copyToClipboard}
                                                className="px-3 py-1 bg-blue-500 text-white rounded hover:bg-blue-600 transition-colors"
                                            >
                                                <i className="fas fa-copy mr-1"></i>
                                                Copy
                                            </button>
                                            <button
                                                onClick={downloadSong}
                                                className="px-3 py-1 bg-green-500 text-white rounded hover:bg-green-600 transition-colors"
                                            >
                                                <i className="fas fa-download mr-1"></i>
                                                Download
                                            </button>
                                        </div>
                                    </div>
                                    
                                    <div className="song-lyrics">
                                        {generatedSong.lyrics.map((line, index) => (
                                            <div 
                                                key={index} 
                                                className="song-line text-white mb-2"
                                                style={{ animationDelay: `${index * 0.1}s` }}
                                            >
                                                {line}
                                            </div>
                                        ))}
                                    </div>
                                </div>
                            )}
                            
                            <div className="mt-8 text-center text-gray-300 text-sm">
                                <p>Enter any prompt to generate unique song lyrics</p>
                                <p className="mt-2">Try prompts like: "space adventure", "rainy day memories", "city lights", "ocean waves"</p>
                            </div>
                        </div>
                    </main>
                </div>
            );
        };

        ReactDOM.render(<SongGenerator />, document.getElementById('root'));
    </script>
</body>
</html>