R-Kentaren commited on
Commit
ab3c2ca
·
verified ·
1 Parent(s): 5f0c346

Create text-to-music.js

Browse files
Files changed (1) hide show
  1. text-to-music.js +74 -0
text-to-music.js ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const axios = require('axios');
2
+
3
+ async function aimusic(prompt, { tags = 'pop, romantic' } = {}) {
4
+ try {
5
+ if (!prompt) throw new Error('Prompt is required');
6
+
7
+ const { data: ai } = await axios.get('https://8pe3nv3qha.execute-api.us-east-1.amazonaws.com/default/llm_chat', {
8
+ params: {
9
+ query: JSON.stringify([
10
+ {
11
+ role: 'system',
12
+ content: 'You are a professional lyricist AI trained to write poetic and rhythmic song lyrics. Respond with lyrics only, using [verse], [chorus], [bridge], and [instrumental] or [inst] tags to structure the song. Use only the tag (e.g., [verse]) without any numbering or extra text (e.g., do not write [verse 1], [chorus x2], etc). Do not add explanations, titles, or any other text outside of the lyrics. Focus on vivid imagery, emotional flow, and strong lyrical rhythm. Refrain from labeling genre or giving commentary. Respond in clean plain text, exactly as if it were a song lyric sheet.'
13
+ },
14
+ {
15
+ role: 'user',
16
+ content: prompt
17
+ }
18
+ ]),
19
+ link: 'writecream.com'
20
+ }
21
+ });
22
+
23
+ const session_hash = Math.random().toString(36).substring(2);
24
+ const d = await axios.post(`https://ace-step-ace-step.hf.space/gradio_api/queue/join?`, {
25
+ data: [
26
+ 240,
27
+ tags,
28
+ ai.response_content,
29
+ 60,
30
+ 15,
31
+ 'euler',
32
+ 'apg',
33
+ 10,
34
+ '',
35
+ 0.5,
36
+ 0,
37
+ 3,
38
+ true,
39
+ false,
40
+ true,
41
+ '',
42
+ 0,
43
+ 0,
44
+ false,
45
+ 0.5,
46
+ null,
47
+ 'none'
48
+ ],
49
+ event_data: null,
50
+ fn_index: 11,
51
+ trigger_id: 45,
52
+ session_hash: session_hash
53
+ });
54
+
55
+ const { data } = await axios.get(`https://ace-step-ace-step.hf.space/gradio_api/queue/data?session_hash=${session_hash}`);
56
+
57
+ let result;
58
+ const lines = data.split('\n\n');
59
+ for (const line of lines) {
60
+ if (line.startsWith('data:')) {
61
+ const d = JSON.parse(line.substring(6));
62
+ if (d.msg === 'process_completed') result = d.output.data[0].url;
63
+ }
64
+ }
65
+
66
+ return result;
67
+ } catch (error) {
68
+ throw new Error(error.message);
69
+ }
70
+ }
71
+
72
+ // Usage:
73
+ const resp = await aimusic('a song about my love for her, with a male vocalist');
74
+ console.log(resp);