abhi1nandy2 commited on
Commit
dc4be7f
·
1 Parent(s): bb6ab4b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +147 -11
app.py CHANGED
@@ -8,6 +8,142 @@ ai_role_dict = {
8
  "sound_engineer": "You are an Experienced Sound Engineer, who can provide expert feedback on the arrangement being used."
9
  }
10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  from tenacity import (
12
  retry,
13
  stop_after_attempt,
@@ -35,9 +171,9 @@ def write_intermediate_outputs(filename, text):
35
 
36
  return sample_file_path
37
 
38
- def write_and_compose(model, api_key, genre, keywords, emotion):
39
  openai.api_key = api_key
40
- 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(genre, keywords, emotion), model)
41
 
42
  query_feedback = '''The Freelance Lyricist submitted these lyrics:
43
 
@@ -68,15 +204,15 @@ Incorporate this feedback, and make suggested changes to the lyrics based on the
68
 
69
  # Workflow: Step 4
70
 
71
- query_composer = '''Given the lyrics of the {} song on {} in the emotion - {} -
72
 
73
  {}
74
 
75
  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)'''
76
 
77
- composition_1 = get_response(ai_role_dict['music_composer'], query_composer.format(genre, keywords, emotion, final_lyrics), model)
78
 
79
- query_sound_engineer = '''Given the lyrics of the {} song on {} in the emotion - {} -
80
 
81
  {}
82
 
@@ -87,9 +223,9 @@ with a Chord Progression and Arrangement (suggested by the Music Composer) -
87
  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"
88
  '''
89
 
90
- composition_2 = get_response(ai_role_dict['sound_engineer'], query_sound_engineer.format(genre, keywords, emotion, final_lyrics, composition_1), model)
91
 
92
- final_query = '''Given the lyrics of the {} song on {} in the emotion - {} -
93
 
94
  {}
95
 
@@ -108,7 +244,7 @@ and further improvements on the Arrangement (suggested by the Sound Engineer)
108
 
109
  '''
110
 
111
- final_response = get_response(ai_role_dict['music_director'], final_query.format(genre, keywords, emotion, final_lyrics, composition_1, composition_2), model)
112
 
113
  final_improvements = final_response.split('==========')[0]
114
 
@@ -132,7 +268,7 @@ description = '''<span style="font-family:Papyrus; font-size:1.5em;">
132
 
133
  # Objective -
134
 
135
- Given specific Genre, Keywords, and Emotion, make a Brand New Song without lifting a finger!
136
 
137
  1. Get lyrics of a new song
138
  2. Get a suitable chord progression
@@ -151,7 +287,7 @@ Given specific Genre, Keywords, and Emotion, make a Brand New Song without lifti
151
 
152
  # Workflow (Intermediate outputs/results are output as downloadable files) -
153
 
154
- 1. Get Inputs from user (OpenAI API Endpoint, API Key, keywords, genre, emotion for the song). Check out [this link](https://platform.openai.com/account/api-keys) to get your API Key
155
  2. Experienced Freelance Lyricist writes a lyrics draft (**see `step_2.txt`**)
156
  3. Experienced Music Director and Experienced Lyricist provide feedback (**see `step_3A.txt` & `step_3B.txt` respectively**)
157
  4. Experienced Freelance Lyricist incorporates the feedback, **Lyrics is finalized here**
@@ -163,7 +299,7 @@ Given specific Genre, Keywords, and Emotion, make a Brand New Song without lifti
163
 
164
  demo = gr.Interface(title = 'Write and Compose brand new Songs using an Elite *AI Music Team*', description = description,
165
  fn=write_and_compose,
166
- inputs=[gr.Radio(["gpt-3.5-turbo", "gpt-4"], value="gpt-3.5-turbo", label = "Choose the OpenAI API Endpoint"), "text", "text", gr.Textbox(label="Keywords (separated by comma)"), "text"], # model, api_key, genre, keywords, emotion
167
  # 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
168
  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
169
  )
 
8
  "sound_engineer": "You are an Experienced Sound Engineer, who can provide expert feedback on the arrangement being used."
9
  }
10
 
11
+ languages = [
12
+ "Afrikaans",
13
+ "Albanian",
14
+ "Amharic",
15
+ "Arabic",
16
+ "Armenian",
17
+ "Assamese",
18
+ "Aymara",
19
+ "Azerbaijani",
20
+ "Bhojpuri",
21
+ "Basque",
22
+ "Belarusian",
23
+ "Bengali",
24
+ "Bambara",
25
+ "Bosnian",
26
+ "Bulgarian",
27
+ "Burmese (Myanmar)",
28
+ "Catalan",
29
+ "Cebuano",
30
+ "Chewa (Chichewa)",
31
+ "Chinese (Simplified)",
32
+ "Chinese (Traditional)",
33
+ "Corsican",
34
+ "Croatian",
35
+ "Czech",
36
+ "Danish",
37
+ "Dogri",
38
+ "Dutch",
39
+ "English",
40
+ "Esperanto",
41
+ "Estonian",
42
+ "Ewe",
43
+ "Finnish",
44
+ "French",
45
+ "Galician",
46
+ "Georgian",
47
+ "German",
48
+ "Greek",
49
+ "Guarani",
50
+ "Gujarati",
51
+ "Haitian Creole",
52
+ "Hausa",
53
+ "Hawaiian",
54
+ "Hebrew",
55
+ "Hindi",
56
+ "Hmong",
57
+ "Hungarian",
58
+ "Icelandic",
59
+ "Igbo",
60
+ "Ilocano",
61
+ "Indonesian",
62
+ "Irish",
63
+ "Italian",
64
+ "Japanese",
65
+ "Javanese",
66
+ "Kannada",
67
+ "Kazakh",
68
+ "Khmer",
69
+ "Kinyarwanda",
70
+ "Konkani",
71
+ "Korean",
72
+ "Krio",
73
+ "Kurdish (Kurmanji)",
74
+ "Kurdish (Sorani)",
75
+ "Kyrgyz",
76
+ "Lao",
77
+ "Latin",
78
+ "Latvian",
79
+ "Lingala",
80
+ "Lithuanian",
81
+ "Luganda",
82
+ "Luxembourgish",
83
+ "Macedonian",
84
+ "Maithili",
85
+ "Malagasy",
86
+ "Malay",
87
+ "Malayalam",
88
+ "Maldivian (Dhivehi)",
89
+ "Maltese",
90
+ "Māori (Maori)",
91
+ "Marathi",
92
+ "Meitei (Manipuri, Meiteilon)",
93
+ "Mizo",
94
+ "Mongolian",
95
+ "Nepali",
96
+ "Northern Sotho (Sepedi)",
97
+ "Norwegian (Bokmål)",
98
+ "Odia (Oriya)",
99
+ "Oromo",
100
+ "Pashto",
101
+ "Persian",
102
+ "Polish",
103
+ "Portuguese",
104
+ "Punjabi (Gurmukhi)",
105
+ "Quechua",
106
+ "Romanian",
107
+ "Russian",
108
+ "Samoan",
109
+ "Sanskrit",
110
+ "Scottish Gaelic (Scots Gaelic)",
111
+ "Serbian",
112
+ "Shona",
113
+ "Sindhi",
114
+ "Sinhala",
115
+ "Slovak",
116
+ "Slovenian",
117
+ "Somali",
118
+ "Sotho (Sesotho)",
119
+ "Spanish",
120
+ "Sundanese",
121
+ "Swahili",
122
+ "Swedish",
123
+ "Tagalog (Filipino)",
124
+ "Tajik",
125
+ "Tamil",
126
+ "Tatar",
127
+ "Telugu",
128
+ "Thai",
129
+ "Tigrinya",
130
+ "Tsonga",
131
+ "Turkish",
132
+ "Turkmen",
133
+ "Twi",
134
+ "Ukrainian",
135
+ "Urdu",
136
+ "Uyghur",
137
+ "Uzbek",
138
+ "Vietnamese",
139
+ "Welsh",
140
+ "West Frisian (Frisian)",
141
+ "Xhosa",
142
+ "Yiddish",
143
+ "Yoruba",
144
+ "Zulu"
145
+ ]
146
+
147
  from tenacity import (
148
  retry,
149
  stop_after_attempt,
 
171
 
172
  return sample_file_path
173
 
174
+ def write_and_compose(model, api_key, language, genre, keywords, emotion):
175
  openai.api_key = api_key
176
+ 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)
177
 
178
  query_feedback = '''The Freelance Lyricist submitted these lyrics:
179
 
 
204
 
205
  # Workflow: Step 4
206
 
207
+ query_composer = '''Given the lyrics of the {} {} song on {} in the emotion - {} -
208
 
209
  {}
210
 
211
  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)'''
212
 
213
+ composition_1 = get_response(ai_role_dict['music_composer'], query_composer.format(language, genre, keywords, emotion, final_lyrics), model)
214
 
215
+ query_sound_engineer = '''Given the lyrics of the {} {} song on {} in the emotion - {} -
216
 
217
  {}
218
 
 
223
  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"
224
  '''
225
 
226
+ composition_2 = get_response(ai_role_dict['sound_engineer'], query_sound_engineer.format(language, genre, keywords, emotion, final_lyrics, composition_1), model)
227
 
228
+ final_query = '''Given the lyrics of the {} {} song on {} in the emotion - {} -
229
 
230
  {}
231
 
 
244
 
245
  '''
246
 
247
+ final_response = get_response(ai_role_dict['music_director'], final_query.format(language, genre, keywords, emotion, final_lyrics, composition_1, composition_2), model)
248
 
249
  final_improvements = final_response.split('==========')[0]
250
 
 
268
 
269
  # Objective -
270
 
271
+ Given specific Language, Genre, Keywords, and Emotion of your choice, make a Brand New Song without lifting a finger!
272
 
273
  1. Get lyrics of a new song
274
  2. Get a suitable chord progression
 
287
 
288
  # Workflow (Intermediate outputs/results are output as downloadable files) -
289
 
290
+ 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
291
  2. Experienced Freelance Lyricist writes a lyrics draft (**see `step_2.txt`**)
292
  3. Experienced Music Director and Experienced Lyricist provide feedback (**see `step_3A.txt` & `step_3B.txt` respectively**)
293
  4. Experienced Freelance Lyricist incorporates the feedback, **Lyrics is finalized here**
 
299
 
300
  demo = gr.Interface(title = 'Write and Compose brand new Songs using an Elite *AI Music Team*', description = description,
301
  fn=write_and_compose,
302
+ 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
303
  # 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
304
  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
305
  )