Milancheeks abhi1nandy2 commited on
Commit
1f51d96
0 Parent(s):

Duplicate from abhi1nandy2/AI_Music_Team

Browse files

Co-authored-by: Abhilash Nandy <abhi1nandy2@users.noreply.huggingface.co>

Files changed (4) hide show
  1. .gitattributes +34 -0
  2. README.md +13 -0
  3. app.py +307 -0
  4. requirements.txt +2 -0
.gitattributes ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tflite filter=lfs diff=lfs merge=lfs -text
29
+ *.tgz filter=lfs diff=lfs merge=lfs -text
30
+ *.wasm filter=lfs diff=lfs merge=lfs -text
31
+ *.xz filter=lfs diff=lfs merge=lfs -text
32
+ *.zip filter=lfs diff=lfs merge=lfs -text
33
+ *.zst filter=lfs diff=lfs merge=lfs -text
34
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: AI Music Team
3
+ emoji: 🔥
4
+ colorFrom: yellow
5
+ colorTo: green
6
+ sdk: gradio
7
+ sdk_version: 3.27.0
8
+ app_file: app.py
9
+ pinned: false
10
+ duplicated_from: abhi1nandy2/AI_Music_Team
11
+ ---
12
+
13
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,307 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import openai
2
+
3
+
4
+ ai_role_dict = {
5
+ "music_director": "You are an Experienced Music Director who has 15+ Years experience in the industry",
6
+ "lyricist": "You are an Experienced Lyricist, who has written hit songs in several languages",
7
+ "freelance_lyricist": "You are an Experienced Freelance Lyricist, who has helped writing songs in several languages",
8
+ "music_composer": "You are an Experienced Music Composer, who has composed songs of several genre and arrangements over the years",
9
+ "sound_engineer": "You are an Experienced Sound Engineer, who can provide expert feedback on the arrangement being used."
10
+ }
11
+
12
+ languages = [
13
+ "Afrikaans",
14
+ "Albanian",
15
+ "Amharic",
16
+ "Arabic",
17
+ "Armenian",
18
+ "Assamese",
19
+ "Aymara",
20
+ "Azerbaijani",
21
+ "Bhojpuri",
22
+ "Basque",
23
+ "Belarusian",
24
+ "Bengali",
25
+ "Bambara",
26
+ "Bosnian",
27
+ "Bulgarian",
28
+ "Burmese (Myanmar)",
29
+ "Catalan",
30
+ "Cebuano",
31
+ "Chewa (Chichewa)",
32
+ "Chinese (Simplified)",
33
+ "Chinese (Traditional)",
34
+ "Corsican",
35
+ "Croatian",
36
+ "Czech",
37
+ "Danish",
38
+ "Dogri",
39
+ "Dutch",
40
+ "English",
41
+ "Esperanto",
42
+ "Estonian",
43
+ "Ewe",
44
+ "Finnish",
45
+ "French",
46
+ "Galician",
47
+ "Georgian",
48
+ "German",
49
+ "Greek",
50
+ "Guarani",
51
+ "Gujarati",
52
+ "Haitian Creole",
53
+ "Hausa",
54
+ "Hawaiian",
55
+ "Hebrew",
56
+ "Hindi",
57
+ "Hmong",
58
+ "Hungarian",
59
+ "Icelandic",
60
+ "Igbo",
61
+ "Ilocano",
62
+ "Indonesian",
63
+ "Irish",
64
+ "Italian",
65
+ "Japanese",
66
+ "Javanese",
67
+ "Kannada",
68
+ "Kazakh",
69
+ "Khmer",
70
+ "Kinyarwanda",
71
+ "Konkani",
72
+ "Korean",
73
+ "Krio",
74
+ "Kurdish (Kurmanji)",
75
+ "Kurdish (Sorani)",
76
+ "Kyrgyz",
77
+ "Lao",
78
+ "Latin",
79
+ "Latvian",
80
+ "Lingala",
81
+ "Lithuanian",
82
+ "Luganda",
83
+ "Luxembourgish",
84
+ "Macedonian",
85
+ "Maithili",
86
+ "Malagasy",
87
+ "Malay",
88
+ "Malayalam",
89
+ "Maldivian (Dhivehi)",
90
+ "Maltese",
91
+ "Māori (Maori)",
92
+ "Marathi",
93
+ "Meitei (Manipuri, Meiteilon)",
94
+ "Mizo",
95
+ "Mongolian",
96
+ "Nepali",
97
+ "Northern Sotho (Sepedi)",
98
+ "Norwegian (Bokmål)",
99
+ "Odia (Oriya)",
100
+ "Oromo",
101
+ "Pashto",
102
+ "Persian",
103
+ "Polish",
104
+ "Portuguese",
105
+ "Punjabi (Gurmukhi)",
106
+ "Quechua",
107
+ "Romanian",
108
+ "Russian",
109
+ "Samoan",
110
+ "Sanskrit",
111
+ "Scottish Gaelic (Scots Gaelic)",
112
+ "Serbian",
113
+ "Shona",
114
+ "Sindhi",
115
+ "Sinhala",
116
+ "Slovak",
117
+ "Slovenian",
118
+ "Somali",
119
+ "Sotho (Sesotho)",
120
+ "Spanish",
121
+ "Sundanese",
122
+ "Swahili",
123
+ "Swedish",
124
+ "Tagalog (Filipino)",
125
+ "Tajik",
126
+ "Tamil",
127
+ "Tatar",
128
+ "Telugu",
129
+ "Thai",
130
+ "Tigrinya",
131
+ "Tsonga",
132
+ "Turkish",
133
+ "Turkmen",
134
+ "Twi",
135
+ "Ukrainian",
136
+ "Urdu",
137
+ "Uyghur",
138
+ "Uzbek",
139
+ "Vietnamese",
140
+ "Welsh",
141
+ "West Frisian (Frisian)",
142
+ "Xhosa",
143
+ "Yiddish",
144
+ "Yoruba",
145
+ "Zulu"
146
+ ]
147
+
148
+ from tenacity import (
149
+ retry,
150
+ stop_after_attempt,
151
+ wait_random_exponential,
152
+ ) # for exponential backoff
153
+
154
+ @retry(wait=wait_random_exponential(min=1, max=100), stop=stop_after_attempt(8))
155
+ def get_response(ai_role, query, model):
156
+
157
+ response = openai.ChatCompletion.create(
158
+ model=model,
159
+ messages=[
160
+ {"role": "system", "content": "{}".format(ai_role)},
161
+ {"role": "user", "content": "{}".format(query)},
162
+ ]
163
+ )
164
+
165
+ return response['choices'][0]['message']['content']
166
+
167
+ def write_intermediate_outputs(filename, text):
168
+ with open(filename, 'w') as fw:
169
+ fw.write(text)
170
+
171
+ sample_file_path = f'./{filename}'
172
+
173
+ return sample_file_path
174
+
175
+ def write_and_compose(model, api_key, language, genre, keywords, emotion):
176
+ openai.api_key = api_key
177
+ initial_lyrics = get_response(ai_role_dict['freelance_lyricist'], "Write structured lyrics of a {} {} song with the following keywords - {}, and use the following emotion - {}".format(language, genre, keywords, emotion), model)
178
+
179
+ query_feedback = '''The Freelance Lyricist submitted these lyrics:
180
+
181
+ {}
182
+
183
+ Provide suitable feedback (in bullet-points)
184
+ '''
185
+
186
+ feedback1 = get_response(ai_role_dict['music_director'], query_feedback.format(initial_lyrics), model)
187
+ feedback2 = get_response(ai_role_dict['lyricist'], query_feedback.format(initial_lyrics), model)
188
+
189
+ # Workflow: Step 3
190
+
191
+ feedback = '''After seeing the lyrics you initially submitted -
192
+
193
+ {}
194
+
195
+ the music director provided the following feedback -
196
+ {}
197
+
198
+ the lyricist provided the following feedback as well -
199
+ {}
200
+
201
+ Incorporate this feedback, and make suggested changes to the lyrics based on the feedback only
202
+ '''
203
+
204
+ final_lyrics = get_response(ai_role_dict['freelance_lyricist'], feedback.format(initial_lyrics, feedback1, feedback2), model)
205
+
206
+ # Workflow: Step 4
207
+
208
+ query_composer = '''Given the lyrics of the {} {} song on {} in the emotion - {} -
209
+
210
+ {}
211
+
212
+ write a suitable chord progression (for each line of the same lyrics), followed by the suitable arrangement required to sing and record the song (in bullet points)'''
213
+
214
+ composition_1 = get_response(ai_role_dict['music_composer'], query_composer.format(language, genre, keywords, emotion, final_lyrics), model)
215
+
216
+ query_sound_engineer = '''Given the lyrics of the {} {} song on {} in the emotion - {} -
217
+
218
+ {}
219
+
220
+ with a Chord Progression and Arrangement (suggested by the Music Composer) -
221
+
222
+ {}
223
+
224
+ could you write improvements that could be made to the Arrangement (in bullet points)? If the current arrangement is upto the mark, write "No change in the arrangement required"
225
+ '''
226
+
227
+ composition_2 = get_response(ai_role_dict['sound_engineer'], query_sound_engineer.format(language, genre, keywords, emotion, final_lyrics, composition_1), model)
228
+
229
+ final_query = '''Given the lyrics of the {} {} song on {} in the emotion - {} -
230
+
231
+ {}
232
+
233
+ with a Chord Progression and Arrangement (suggested by the Music Composer) -
234
+
235
+ {}
236
+
237
+ and further improvements on the Arrangement (suggested by the Sound Engineer)
238
+
239
+ {}
240
+
241
+ - suggest any further improvements that could be made to the (a) Chord Progression (b) Arrangement.
242
+ - After that, Write 10 "="s in the next line
243
+ - After that, Write the final Chord Progression and Arrangement
244
+ - Also, write a suitable title for the song
245
+
246
+ '''
247
+
248
+ final_response = get_response(ai_role_dict['music_director'], final_query.format(language, genre, keywords, emotion, final_lyrics, composition_1, composition_2), model)
249
+
250
+ final_improvements = final_response.split('==========')[0]
251
+
252
+ final_chord_prog_and_composition = final_response.split('==========')[-1]
253
+
254
+ # return initial_lyrics, feedback1, feedback2, final_lyrics, composition_1, composition_2, final_improvements, final_chord_prog_and_composition
255
+
256
+ output_file_list = []
257
+ output_file_list.append(write_intermediate_outputs('step_2.txt', initial_lyrics))
258
+ output_file_list.append(write_intermediate_outputs('step_3A.txt', feedback1))
259
+ output_file_list.append(write_intermediate_outputs('step_3B.txt', feedback2))
260
+ output_file_list.append(write_intermediate_outputs('step_5.txt', composition_1))
261
+ output_file_list.append(write_intermediate_outputs('step_6.txt', composition_2))
262
+ output_file_list.append(write_intermediate_outputs('step_7.txt', final_improvements))
263
+
264
+ return final_lyrics, final_chord_prog_and_composition, output_file_list
265
+
266
+ import gradio as gr
267
+
268
+ description = '''<span style="font-family:Papyrus; font-size:1.5em;">
269
+
270
+ # Objective -
271
+
272
+ Given specific Language, Genre, Keywords, and Emotion of your choice, make a Brand New Song without lifting a finger!
273
+
274
+ 1. Get lyrics of a new song
275
+ 2. Get a suitable chord progression
276
+ 3. Get a suitable musical arrangement for singing and recording the song
277
+ 4. Cherry on the top - Get a suitable song title!
278
+
279
+
280
+ # AI Music Team is composed of several GPT agents with the following "personas" -
281
+
282
+ 1. Experienced Music Director who has 15+ Years experience in the industry
283
+ 2. Experienced Lyricist, who has written hit songs in several languages
284
+ 3. Experienced Freelance Lyricist, who has helped writing songs in several languages
285
+ 4. Experienced Music Composer, who has composed songs of several genre and arrangements over the years
286
+ 5. Experienced Sound Engineer, who can provide expert feedback on the arrangement being used
287
+
288
+
289
+ # Workflow (Intermediate outputs/results are output as downloadable files) -
290
+
291
+ 1. Get Inputs from user (OpenAI API Endpoint, API Key, language, keywords, genre, emotion for the song). Check out [this link](https://platform.openai.com/account/api-keys) to get your API Key
292
+ 2. Experienced Freelance Lyricist writes a lyrics draft (**see `step_2.txt`**)
293
+ 3. Experienced Music Director and Experienced Lyricist provide feedback (**see `step_3A.txt` & `step_3B.txt` respectively**)
294
+ 4. Experienced Freelance Lyricist incorporates the feedback, **Lyrics is finalized here**
295
+ 5. Experienced Music Composer will provide a chord progression, and an arrangement of instruments (**see `step_5.txt`**)
296
+ 6. Experienced Sound Engineer will provide ways to improve on the existing arrangement (**see `step_6.txt`**)
297
+ 7. Finally, Music Director will provide improvements (**see `step_7.txt`**), resulting in the **final Chord Progression, Arrangement, and Song Title**
298
+ </span>
299
+ '''
300
+
301
+ demo = gr.Interface(title = 'Write and Compose brand new Songs using an Elite *AI Music Team*', description = description,
302
+ fn=write_and_compose,
303
+ inputs=[gr.Radio(["gpt-3.5-turbo", "gpt-4"], value="gpt-3.5-turbo", label = "Choose the OpenAI API Endpoint"), gr.Textbox(label="API Key (Check out [this link](https://platform.openai.com/account/api-keys) to get your API Key)"), gr.Dropdown(choices=languages, value='English', label="Language of the lyrics"), gr.Textbox(label="Genre"), gr.Textbox(label="Keywords (separated by comma)"), gr.Textbox(label="Emotion")], # model, api_key, language, genre, keywords, emotion
304
+ # outputs=[gr.Textbox(label="Lyrics after Step #2"), gr.Textbox(label="Feedback provided by Music Director in Step #3"), gr.Textbox(label="Feedback provided by Lyricist in Step #3"), gr.Textbox(label="Final Lyrics of the song after Step #4"), gr.Textbox(label="Chord Progression and Arrangement suggested by Music Composer in Step #5"), gr.Textbox(label="Arrangement improvements suggested by Sound Engineer in Step #6"), gr.Textbox(label="Chord and Arrangement improvements suggested by Music Director in Step #7"), gr.Textbox(label="Final Chord Progression, Arrangment, and Song Title")], # initial_lyrics, feedback1, feedback2, final_lyrics, composition_1, composition_2, final_improvements, final_chord_prog_and_composition
305
+ outputs=[gr.Textbox(label="Final Lyrics of the song after Step #4"), gr.Textbox(label="Final Chord Progression, Arrangement, and Song Title"), gr.File(label='Intermediate Outputs')], # initial_lyrics, feedback1, feedback2, final_lyrics, composition_1, composition_2, final_improvements, final_chord_prog_and_composition
306
+ )
307
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ openai
2
+ tenacity