flen-crypto commited on
Commit
edb69f0
·
verified ·
1 Parent(s): f7be4c3

generate random track descriptions via an animated dice button, with suggestions taken from using Deepseeks API

Browse files
Files changed (3) hide show
  1. analytics.html +1 -2
  2. generator.html +67 -8
  3. script.js +45 -1
analytics.html CHANGED
@@ -91,8 +91,7 @@
91
  <script src="script.js"></script>
92
  <script>
93
  feather.replace();
94
-
95
- // Initialize charts
96
  document.addEventListener('DOMContentLoaded', function() {
97
  // Streams Chart
98
  const streamsCtx = document.getElementById('streamsChart').getContext('2d');
 
91
  <script src="script.js"></script>
92
  <script>
93
  feather.replace();
94
+ // Initialize charts
 
95
  document.addEventListener('DOMContentLoaded', function() {
96
  // Streams Chart
97
  const streamsCtx = document.getElementById('streamsChart').getContext('2d');
generator.html CHANGED
@@ -26,12 +26,16 @@
26
  <div class="glass rounded-2xl p-8 mb-8">
27
  <div class="flex items-center justify-between mb-6">
28
  <h2 class="text-2xl font-semibold text-white">Enter Your Music Prompt</h2>
29
- <button id="voice-btn" class="bg-purple-600 hover:bg-purple-700 p-3 rounded-full transition-all">
30
- <i data-feather="mic" class="text-white"></i>
31
- </button>
 
 
 
 
 
32
  </div>
33
-
34
- <div class="space-y-6">
35
  <div>
36
  <label class="block text-gray-300 mb-2">Describe your track:</label>
37
  <textarea
@@ -201,13 +205,68 @@
201
  <script src="script.js"></script>
202
  <script>
203
  feather.replace();
204
-
205
- // Voice recognition
206
  const voiceBtn = document.getElementById('voice-btn');
207
  const promptTextarea = document.getElementById('music-prompt');
208
  const voiceRecognition = new VoiceRecognition();
209
 
210
- voiceBtn.addEventListener('click', function() {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
211
  if (voiceRecognition.isListening) {
212
  voiceRecognition.stopListening();
213
  voiceBtn.innerHTML = '<i data-feather="mic" class="text-white"></i>';
 
26
  <div class="glass rounded-2xl p-8 mb-8">
27
  <div class="flex items-center justify-between mb-6">
28
  <h2 class="text-2xl font-semibold text-white">Enter Your Music Prompt</h2>
29
+ <div class="flex gap-2">
30
+ <button id="dice-btn" class="bg-purple-600 hover:bg-purple-700 p-3 rounded-full transition-all">
31
+ <i data-feather="dice" class="text-white"></i>
32
+ </button>
33
+ <button id="voice-btn" class="bg-purple-600 hover:bg-purple-700 p-3 rounded-full transition-all">
34
+ <i data-feather="mic" class="text-white"></i>
35
+ </button>
36
+ </div>
37
  </div>
38
+ <div class="space-y-6">
 
39
  <div>
40
  <label class="block text-gray-300 mb-2">Describe your track:</label>
41
  <textarea
 
205
  <script src="script.js"></script>
206
  <script>
207
  feather.replace();
208
+ // Dice button for random prompts
209
+ const diceBtn = document.getElementById('dice-btn');
210
  const voiceBtn = document.getElementById('voice-btn');
211
  const promptTextarea = document.getElementById('music-prompt');
212
  const voiceRecognition = new VoiceRecognition();
213
 
214
+ diceBtn.addEventListener('click', async function() {
215
+ // Add rotation animation
216
+ diceBtn.classList.add('animate-spin');
217
+
218
+ try {
219
+ const response = await fetch('https://api.deepseek.com/v1/chat/completions', {
220
+ method: 'POST',
221
+ headers: {
222
+ 'Content-Type': 'application/json',
223
+ 'Authorization': 'Bearer YOUR_DEEPSEEK_API_KEY' // Replace with actual API key
224
+ },
225
+ body: JSON.stringify({
226
+ model: 'deepseek-chat',
227
+ messages: [
228
+ {
229
+ role: 'user',
230
+ content: 'Generate 5 creative and diverse music track descriptions for AI music generation. Include different genres, moods, and styles. Format as a JSON array of strings.'
231
+ }
232
+ ],
233
+ max_tokens: 500,
234
+ temperature: 0.8
235
+ })
236
+ });
237
+
238
+ if (!response.ok) {
239
+ throw new Error('Failed to fetch random prompts');
240
+ }
241
+
242
+ const data = await response.json();
243
+ const prompts = JSON.parse(data.choices[0].message.content);
244
+
245
+ // Pick a random prompt from the generated ones
246
+ const randomPrompt = prompts[Math.floor(Math.random() * prompts.length)];
247
+ promptTextarea.value = randomPrompt;
248
+
249
+ // Remove animation after a delay
250
+ setTimeout(() => {
251
+ diceBtn.classList.remove('animate-spin');
252
+ }, 1000);
253
+
254
+ } catch (error) {
255
+ console.error('Error fetching random prompt:', error);
256
+ // Fallback to predefined prompts if API fails
257
+ const fallbackPrompts = [
258
+ "Melodic deep house track with ethereal female vocals, perfect for sunset drives and chill vibes",
259
+ "Aggressive dubstep with heavy bass drops and glitch effects, optimized for festival crowds",
260
+ "Lo-fi hip hop beat with vinyl crackle and smooth jazz samples, ideal for study sessions",
261
+ "Upbeat pop anthem with catchy hooks and electronic elements, radio-ready production",
262
+ "Cinematic orchestral piece with epic brass and string sections, suitable for film trailers"
263
+ ];
264
+ const randomPrompt = fallbackPrompts[Math.floor(Math.random() * fallbackPrompts.length)];
265
+ promptTextarea.value = randomPrompt;
266
+ diceBtn.classList.remove('animate-spin');
267
+ }
268
+ });
269
+ voiceBtn.addEventListener('click', function() {
270
  if (voiceRecognition.isListening) {
271
  voiceRecognition.stopListening();
272
  voiceBtn.innerHTML = '<i data-feather="mic" class="text-white"></i>';
script.js CHANGED
@@ -139,8 +139,52 @@ class VoiceRecognition {
139
  }
140
  }
141
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
142
 
143
  // Export for use in other modules
144
  window.MusicAPI = MusicAPI;
145
  window.StorageManager = StorageManager;
146
- window.VoiceRecognition = VoiceRecognition;
 
 
139
  }
140
  }
141
  }
142
+ // Random prompt generator using Deepseek API
143
+ class RandomPromptGenerator {
144
+ static async generateRandomPrompts() {
145
+ try {
146
+ const response = await fetch('https://api.deepseek.com/v1/chat/completions', {
147
+ method: 'POST',
148
+ headers: {
149
+ 'Content-Type': 'application/json',
150
+ 'Authorization': 'Bearer YOUR_DEEPSEEK_API_KEY' // Replace with actual API key
151
+ },
152
+ body: JSON.stringify({
153
+ model: 'deepseek-chat',
154
+ messages: [
155
+ {
156
+ role: 'user',
157
+ content: 'Generate 5 diverse and creative music track descriptions for AI music generation. Include different genres like electronic, pop, rock, hip-hop, and experimental styles. Format as a JSON array of strings.'
158
+ }
159
+ ],
160
+ max_tokens: 500,
161
+ temperature: 0.9
162
+ })
163
+ });
164
+
165
+ if (!response.ok) {
166
+ throw new Error('Deepseek API request failed');
167
+ }
168
+
169
+ const data = await response.json();
170
+ return JSON.parse(data.choices[0].message.content);
171
+ } catch (error) {
172
+ console.error('Random prompt generation error:', error);
173
+ // Return fallback prompts
174
+ return [
175
+ "Dreamy synthwave with nostalgic 80s vibes and pulsating arpeggios, perfect for night driving',
176
+ "Emotional piano ballad with heartfelt male vocals and string accompaniment, cinematic quality',
177
+ "Hard-hitting trap beat with 808 bass and crisp hi-hats, perfect for urban radio play',
178
+ "Ambient soundscape with field recordings and atmospheric pads, meditation and relaxation focus",
179
+ "Funky disco track with groovy bassline and brass stabs, dance floor energy optimized',
180
+ "Acoustic folk song with fingerpicking guitar and harmonizing vocals, campfire intimate feel"
181
+ ];
182
+ }
183
+ }
184
+ }
185
 
186
  // Export for use in other modules
187
  window.MusicAPI = MusicAPI;
188
  window.StorageManager = StorageManager;
189
+ window.VoiceRecognition = VoiceRecognition;
190
+ window.RandomPromptGenerator = RandomPromptGenerator;