anycoder-67e83bca / index.html
Isaac-808's picture
Upload folder using huggingface_hub
7fcd65f verified
Raw History Blame Contribute Delete
14.4 kB
<!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>