Francesco commited on
Commit
d78781e
1 Parent(s): ccabaa8

new version that reccomands three songs and then we take a random one

Browse files
Files changed (3) hide show
  1. app.py +6 -4
  2. prompts/bot_with_summary.prompt +6 -5
  3. temp.ipynb +79 -53
app.py CHANGED
@@ -13,6 +13,7 @@ from langchain.embeddings.openai import OpenAIEmbeddings
13
 
14
  from data import load_db
15
  from names import DATASET_ID, MODEL_ID
 
16
 
17
 
18
  @st.cache_resource
@@ -46,7 +47,7 @@ def init():
46
 
47
  for movie, songs in data.items():
48
  for song in songs:
49
- movie_and_name = f"{movie};{song['name'].lower()}"
50
  songs_str += f"{movie_and_name}:{song['text']}\n"
51
  movies_and_names_to_songs[movie_and_name] = song
52
 
@@ -66,9 +67,10 @@ placeholder_emotions = st.empty()
66
  placeholder = st.empty()
67
 
68
  def get_emotions(songs_str, user_input):
69
- key = chain.run(songs=songs_str, user_input=user_input)
70
- doc = movies_and_names_to_songs[key]
71
- print(f"Reply: {key}")
 
72
  with placeholder:
73
  embed_url = doc["embed_url"]
74
  iframe_html = f'<iframe src="{embed_url}" style="border:0"> </iframe>'
 
13
 
14
  from data import load_db
15
  from names import DATASET_ID, MODEL_ID
16
+ import random
17
 
18
 
19
  @st.cache_resource
 
47
 
48
  for movie, songs in data.items():
49
  for song in songs:
50
+ movie_and_name = f"{movie};{song['name']}".lower()
51
  songs_str += f"{movie_and_name}:{song['text']}\n"
52
  movies_and_names_to_songs[movie_and_name] = song
53
 
 
67
  placeholder = st.empty()
68
 
69
  def get_emotions(songs_str, user_input):
70
+ res = chain.run(songs=songs_str, user_input=user_input)
71
+ song_key = random.choice(eval(res))
72
+ doc = movies_and_names_to_songs[song_key.lower()]
73
+ print(f"Reply: {res}, chosen: {song_key}")
74
  with placeholder:
75
  embed_url = doc["embed_url"]
76
  iframe_html = f'<iframe src="{embed_url}" style="border:0"> </iframe>'
prompts/bot_with_summary.prompt CHANGED
@@ -3,11 +3,12 @@ If you don't find a match provide your best guess. Try to look at each song's th
3
 
4
  {songs}
5
 
6
- Given a input, output three songs that goes well with the input.
7
 
8
- For example:
9
  Input: "Today I am not feeling great"
10
- [<MOVIE_NAME>;<SONG_TITLE>, <MOVIE_NAME>;<SONG_TITLE>, <MOVIE_NAME>;<SONG_TITLE>]
11
  Input: "I am great today"
12
- [<MOVIE_NAME>;<SONG_TITLE>, <MOVIE_NAME>;<SONG_TITLE>, <MOVIE_NAME>;<SONG_TITLE>]
13
- Input: {user_input}
 
 
3
 
4
  {songs}
5
 
6
+ Given a input, output three songs as a list that goes well with the input. The list of songs will be used to retrieve them from our database. The type of the reply is List[str, str, str]. Please follow the following example formats
7
 
8
+ Examples:
9
  Input: "Today I am not feeling great"
10
+ ["<MOVIE_NAME>;<SONG_TITLE>", "<MOVIE_NAME>;<SONG_TITLE>", "<MOVIE_NAME>;<SONG_TITLE>"]
11
  Input: "I am great today"
12
+ ["<MOVIE_NAME>;<SONG_TITLE>", "<MOVIE_NAME>;<SONG_TITLE>", "<MOVIE_NAME>;<SONG_TITLE>"]
13
+
14
+ The user input is {user_input}
temp.ipynb CHANGED
@@ -13,7 +13,7 @@
13
  },
14
  {
15
  "cell_type": "code",
16
- "execution_count": 74,
17
  "id": "b1a6a020",
18
  "metadata": {
19
  "scrolled": true
@@ -23,7 +23,9 @@
23
  "name": "stderr",
24
  "output_type": "stream",
25
  "text": [
26
- "/"
 
 
27
  ]
28
  },
29
  {
@@ -38,7 +40,7 @@
38
  "name": "stderr",
39
  "output_type": "stream",
40
  "text": [
41
- "-"
42
  ]
43
  },
44
  {
@@ -89,7 +91,7 @@
89
  },
90
  {
91
  "cell_type": "markdown",
92
- "id": "b5e75439",
93
  "metadata": {},
94
  "source": [
95
  "## Using similarity search"
@@ -191,7 +193,7 @@
191
  },
192
  {
193
  "cell_type": "markdown",
194
- "id": "942b0809",
195
  "metadata": {},
196
  "source": [
197
  "## Using all the songs emotions in the prommpt"
@@ -199,26 +201,29 @@
199
  },
200
  {
201
  "cell_type": "code",
202
- "execution_count": 295,
203
- "id": "50044e35",
204
  "metadata": {},
205
  "outputs": [],
206
  "source": [
207
  "import json\n",
 
 
 
208
  "\n",
209
  "prompt = PromptTemplate(\n",
210
  " input_variables=[\"songs\", \"user_input\"],\n",
211
  " template=Path(\"prompts/bot_with_summary.prompt\").read_text(),\n",
212
  ")\n",
213
  "\n",
214
- "llm = ChatOpenAI(temperature=1)\n",
215
  "\n",
216
  "chain = LLMChain(llm=llm, prompt=prompt)"
217
  ]
218
  },
219
  {
220
  "cell_type": "markdown",
221
- "id": "873c7f81",
222
  "metadata": {},
223
  "source": [
224
  "Let's create the songs string"
@@ -226,8 +231,8 @@
226
  },
227
  {
228
  "cell_type": "code",
229
- "execution_count": 296,
230
- "id": "009caaaf",
231
  "metadata": {},
232
  "outputs": [],
233
  "source": [
@@ -239,8 +244,8 @@
239
  },
240
  {
241
  "cell_type": "code",
242
- "execution_count": 297,
243
- "id": "afb081f7",
244
  "metadata": {
245
  "scrolled": true
246
  },
@@ -257,78 +262,99 @@
257
  },
258
  {
259
  "cell_type": "code",
260
- "execution_count": 301,
261
- "id": "963f2237",
 
 
 
 
 
 
 
 
 
 
262
  "metadata": {},
263
  "outputs": [
264
  {
265
  "data": {
266
  "text/plain": [
267
- "\"aladdin;friend like me:excitement, happiness, humor, friendliness, generosity, willingness, eagerness, confidence\\naladdin;arabian nights:nostalgic, adventurous, exotic, intense, romantic, mysterious, whimsical, passionate\\naladdin;a whole new world:wonder, joy, excitement, adventure, romance, freedom, happiness, awe\\naladdin;one jump ahead:Thrill, fear, desperation, humor, defiance, friendship, hunger, rebellion.\\naladdin (live-action);a whole new world:nostalgia, wonder, excitement, joy, romance, adventure, hope, inspiration\\naladdin (live-action);a whole new world (end title):joy, wonder, excitement, adventure, love, freedom, exhilaration, enchantment\\naladdin (live-action);friend like me:excitement, confidence, generosity, humor, friendliness, helpfulness, empowerment, joyfulness\\naladdin (live-action);one jump ahead:excitement, fear, desperation, humor, defiance, loneliness, camaraderie, determination\\naladdin (live-action);speechless (full):determination, empowerment, resilience, strength, defiance, courage, passion, perseverance\\naladdin: the return of jafar;arabian nights:excitement, wonder, adventure, awe, joy, fascination, thrill, curiosity\\nbeauty and the beast;belle:calm, content, curious, dreamy, happy, hopeful, romantic, whimsical\\nbeauty and the beast;be our guest:joy, excitement, hospitality, gratitude, entertainment, nostalgia, comfort, satisfaction\\nbrave;touch the sky:hopeful, adventurous, determined, inspired, free-spirited, empowered, awe-struck, exhilarated\\ncoco;remember me (dúo):nostalgia, love, longing, sadness, hope, comfort, devotion, perseverance\\ncoco;remember me (ernesto de la cruz):longing, separation, love, devotion, sadness, comfort, hope, reminiscence\\ncoco;the world es mi familia:joy, happiness, excitement, love, gratitude, belonging, unity, celebration\\ncoco;un poco loco:confusion, love, amusement, uncertainty, joy, surprise, frustration, whimsy\\ndescendants 3;dig a little deeper:Hope, Acceptance, Empowerment, Encouragement, Determination, Inspiration, Resilience, Confidence.\\nencanto;the family madrigal:joy, excitement, wonder, confusion, love, pride, nostalgia, humor\\nencanto;surface pressure:strength, confidence, anxiety, pressure, worry, fear, determination, resilience\\nencanto;two oruguitas:love, yearning, hunger, fear, anticipation, change, trust, growth\\nencanto;we don't talk about bruno:joy, fear, confusion, anxiety, frustration, curiosity, anger, humor\\nencanto;what else can i do?:unexpected, beautiful, practiced, carnivorous, new, sick of pretty, rising, changing minds\\nencanto;waiting on a miracle:upset, mad, regret, sad, fine, longing, hopeful, impatient\\nenchanted;happy working song:joy, cheerfulness, contentment, enthusiasm, satisfaction, excitement, pleasure, happiness\\nenchanted;so close:romantic, hopeful, longing, joy, fear, sadness, content, nostalgia\\nenchanted;that's how you know:love, happiness, affection, devotion, passion, adoration, appreciation, romance\\nfrozen;do you want to build a snowman?:loneliness, longing, sadness, nostalgia, hope, perseverance, friendship, playfulness\\nfrozen;for the first time in forever:excited, hopeful, nervous, happy, anxious, optimistic, romantic, determined\\nfrozen;in summer:joy, anticipation, excitement, happiness, nostalgia, humor, contentment, playfulness\\nfrozen;let it go:isolation, determination, freedom, empowerment, resilience, confidence, defiance, happiness\\nfrozen;love is an open door:joy, excitement, love, happiness, contentment, connection, optimism, anticipation\\nfrozen 2;all is found:nostalgia, safety, discovery, fear, magic, bravery, loss, hope.\\nfrozen 2;into the unknown:confusion, fear, hesitation, loneliness, longing, uncertainty, curiosity, determination\\nfrozen 2;lost in the woods:wondering, lost, confused, sad, longing, hopeful, uncertain, anxious\\nfrozen 2;show yourself:trembling, familiar, sense of belonging, longing, certainty, purpose, anticipation, empowerment\\nfrozen 2;some things never change:nostalgia, love, uncertainty, hope, contentment, joy, apprehension, gratitude\\nfrozen 2;when i am older:nostalgia, comfort, curiosity, fear, acceptance, wisdom, optimism, reassurance\\nhercules;a star is born:excitement, triumph, hope, inspiration, admiration, joy, pride, determination\\nhercules;go the distance:Hopeful, determined, inspired, optimistic, longing, driven, passionate, adventurous.\\nhercules;zero to hero:excitement, admiration, joy, pride, amazement, awe, gratitude, inspiration\\nhigh school musical;start of something new:hopeful, excited, enamored, inspired, optimistic, joyful, eager, elated\\nhigh school musical;we're all in this together:joyful, celebratory, unity, energetic, enthusiastic, uplifting, optimistic, empowering\\nhsm: the musical: the series;all i want:love, disappointment, frustration, confusion, doubt, loneliness, longing, self-reflection.\\nhsm: the musical: the series (season 2);the rose song:Wonder, doubt, love, trapped, beauty, freedom, growth, empowerment.\\nhsm: the musical: the series (season 3);you never know:hope, anticipation, excitement, mystery, adventure, positivity, curiosity, wonder\\nthe jungle book;the bare necessities:joy, contentment, relaxation, playfulness, curiosity, wonder, gratitude, simplicity\\nthe lion king;can you feel the love tonight:romantic, sweet, magical, disastrous, truthful, hesitant, hopeful, doomed\\nthe lion king;circle of life:hope, despair, love, faith, wonder, awe, nostalgia, inspiration\\nthe lion king;hakuna matata:joy, carefree, contentment, relief, humor, lightheartedness, friendship, acceptance\\nthe lion king;i just can't wait to be king:excitement, ambition, defiance, freedom, confidence, anticipation, joy, triumph\\nthe lion king (live-action);can you feel the love tonight:romantic, peaceful, harmonious, uncertain, fearful, hopeful, longing, doomed\\nthe lion king (live-action);circle of life:Joy, wonder, awe, hope, love, nostalgia, inspiration, contentment.\\nthe lion king (live-action);hakuna matata:joy, happiness, carefree, contentment, humor, playfulness, relaxation, comfort\\nthe lion king (live-action);i just can't wait to be king:Excitement, Ambition, Confidence, Defiance, Rebellion, Anticipation, Joy, Empowerment\\nthe little mermaid;kiss the girl:excitement, curiosity, desire, shyness, sadness, regret, anticipation, courage\\nthe little mermaid;part of your world:wonder, desire, longing, curiosity, joy, hope, anticipation, yearning\\nthe little mermaid;poor unfortunate souls:nasty, repentant, magic, sad, lonely, bored, withdrawn, busy\\nthe little mermaid;under the sea:happy, joyful, playful, carefree, energetic, lively, whimsical, adventurous\\nmary poppins;supercalifragilisticexpialidocious:joy, excitement, playfulness, nostalgia, humor, confidence, charm, love\\nmoana;how far i'll go:nostalgia, longing, determination, curiosity, confusion, satisfaction, pride, uncertainty\\nmoana;where you are:happiness, contentment, tradition, pride, belonging, determination, nostalgia, joy\\nmoana;you're welcome:adorable, confident, proud, playful, grateful, boastful, humorous, friendly\\nmulan;a girl worth fighting for:nostalgia, camaraderie, humor, determination, longing, admiration, optimism, romance\\nmulan;honor to us all:determination, pride, obedience, tradition, anxiety, hope, honor, cultural expectations\\nmulan;reflection:doubt, insecurity, confusion, sadness, frustration, longing, self-discovery, acceptance\\nmulan (live-action);reflection:confusion, frustration, identity, longing, self-discovery, vulnerability, authenticity, empowerment\\npinocchio;when you wish upon a star:hopeful, optimistic, dreamy, inspired, happy, content, fulfilled, grateful\\npinocchio (live-action);when you wish upon a star:hopeful, optimistic, joyful, fulfilled, inspired, grateful, content, peaceful\\npocahontas;colors of the wind:wonder, defiance, connection, appreciation, curiosity, empowerment, harmony, respect\\nthe princess and the frog;dig a little deeper:joy, acceptance, self-discovery, contentment, optimism, encouragement, determination, hopefulness\\nthe princess and the frog;down in new orleans (finale):excitement, happiness, joy, celebration, optimism, anticipation, nostalgia, contentment\\nthe princess and the frog;when we're human:excitement, joy, confidence, optimism, contentment, nostalgia, determination, celebration\\nrobin hood;love:nostalgia, love, longing, happiness, sadness, reflection, timelessness, sentimentality\\nsleeping beauty;once upon a dream:nostalgia, love, familiarity, hope, longing, enchantment, romanticism, dreaminess\\ntangled;i see the light:nostalgia, longing, clarity, happiness, wonder, realization, love, fulfillment\\ntangled;i've got a dream:malice, violence, dream, love, humor, optimism, perseverance, unity\\ntangled;mother knows best:protectiveness, fear, warning, love, concern, control, manipulation, persuasion\\ntangled;mother knows best (reprise):Skepticism, confidence, warning, trust, superiority, concern, cynicism, assurance.\\ntarzan;strangers like me:curiosity, familiarity, wonder, desire, longing, excitement, eagerness, awe\\ntarzan;you'll be in my heart:Love, comfort, protection, trust, hope, determination, perseverance, dedication\\ntoy story;you've got a friend in me:friendship, loyalty, comfort, support, love, companionship, perseverance, devotion\\nturning red;1 true love:sadness, love, obsession, longing, devotion, despair, hopelessness, affection\\nturning red;nobody like u:love, joy, friendship, loyalty, excitement, admiration, appreciation, happiness\\nturning red;u know what's up:confidence, determination, motivation, empowerment, excitement, ambition, persuasion, triumph\\n\""
268
  ]
269
  },
270
- "execution_count": 301,
271
  "metadata": {},
272
  "output_type": "execute_result"
273
  }
274
  ],
275
  "source": [
276
- "songs_str"
277
- ]
278
- },
279
- {
280
- "cell_type": "code",
281
- "execution_count": 298,
282
- "id": "a53db65b",
283
- "metadata": {
284
- "scrolled": true
285
- },
286
- "outputs": [],
287
- "source": [
288
- "# movies_and_names_to_songs"
289
  ]
290
  },
291
  {
292
  "cell_type": "code",
293
- "execution_count": 299,
294
- "id": "4ea83493",
295
  "metadata": {},
296
  "outputs": [],
297
  "source": [
298
- "# prompt.format(songs=songs_str, user_input=\"I am feeling great today\")"
 
 
299
  ]
300
  },
301
  {
302
  "cell_type": "code",
303
- "execution_count": 300,
304
- "id": "ba6e1232",
305
- "metadata": {},
306
- "outputs": [],
307
- "source": [
308
- "res = chain.run(songs=songs_str, user_input=\"I need energy\").lower()"
309
- ]
310
- },
311
- {
312
- "cell_type": "raw",
313
- "id": "e909d1a4",
314
  "metadata": {},
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
315
  "source": [
316
- "res"
 
 
 
 
317
  ]
318
  },
319
  {
320
  "cell_type": "code",
321
  "execution_count": null,
322
- "id": "04903a71",
323
  "metadata": {},
324
  "outputs": [],
325
- "source": [
326
- "print(res)\n",
327
- "doc = movies_and_names_to_songs[res]\n",
328
- "\n",
329
- "from IPython.display import IFrame\n",
330
- "IFrame(doc[\"embed_url\"], width=700, height=350)"
331
- ]
332
  }
333
  ],
334
  "metadata": {
 
13
  },
14
  {
15
  "cell_type": "code",
16
+ "execution_count": 2,
17
  "id": "b1a6a020",
18
  "metadata": {
19
  "scrolled": true
 
23
  "name": "stderr",
24
  "output_type": "stream",
25
  "text": [
26
+ "/home/zuppif/miniconda3/envs/activeloop/lib/python3.9/site-packages/deeplake/util/check_latest_version.py:32: UserWarning: A newer version of deeplake (3.4.3) is available. It's recommended that you update to the latest version using `pip install -U deeplake`.\n",
27
+ " warnings.warn(\n",
28
+ "-"
29
  ]
30
  },
31
  {
 
40
  "name": "stderr",
41
  "output_type": "stream",
42
  "text": [
43
+ "\\"
44
  ]
45
  },
46
  {
 
91
  },
92
  {
93
  "cell_type": "markdown",
94
+ "id": "97c3370c",
95
  "metadata": {},
96
  "source": [
97
  "## Using similarity search"
 
193
  },
194
  {
195
  "cell_type": "markdown",
196
+ "id": "8a474a1c",
197
  "metadata": {},
198
  "source": [
199
  "## Using all the songs emotions in the prommpt"
 
201
  },
202
  {
203
  "cell_type": "code",
204
+ "execution_count": 23,
205
+ "id": "c3cb2f3d",
206
  "metadata": {},
207
  "outputs": [],
208
  "source": [
209
  "import json\n",
210
+ "from langchain.chains import LLMChain\n",
211
+ "from langchain.prompts import PromptTemplate\n",
212
+ "from pathlib import Path\n",
213
  "\n",
214
  "prompt = PromptTemplate(\n",
215
  " input_variables=[\"songs\", \"user_input\"],\n",
216
  " template=Path(\"prompts/bot_with_summary.prompt\").read_text(),\n",
217
  ")\n",
218
  "\n",
219
+ "llm = ChatOpenAI(temperature=0.7)\n",
220
  "\n",
221
  "chain = LLMChain(llm=llm, prompt=prompt)"
222
  ]
223
  },
224
  {
225
  "cell_type": "markdown",
226
+ "id": "b1ca9c9c",
227
  "metadata": {},
228
  "source": [
229
  "Let's create the songs string"
 
231
  },
232
  {
233
  "cell_type": "code",
234
+ "execution_count": 24,
235
+ "id": "00416443",
236
  "metadata": {},
237
  "outputs": [],
238
  "source": [
 
244
  },
245
  {
246
  "cell_type": "code",
247
+ "execution_count": 25,
248
+ "id": "e4bf60d4",
249
  "metadata": {
250
  "scrolled": true
251
  },
 
262
  },
263
  {
264
  "cell_type": "code",
265
+ "execution_count": 26,
266
+ "id": "32cd1a47",
267
+ "metadata": {},
268
+ "outputs": [],
269
+ "source": [
270
+ "# prompt.format(songs=songs_str, user_input=\"I am feeling great today\")"
271
+ ]
272
+ },
273
+ {
274
+ "cell_type": "code",
275
+ "execution_count": 30,
276
+ "id": "a056e5e9",
277
  "metadata": {},
278
  "outputs": [
279
  {
280
  "data": {
281
  "text/plain": [
282
+ "'[\"coco;remember me (dúo)\", \"mulan;reflection\", \"frozen;do you want to build a snowman?\"]'"
283
  ]
284
  },
285
+ "execution_count": 30,
286
  "metadata": {},
287
  "output_type": "execute_result"
288
  }
289
  ],
290
  "source": [
291
+ "res = chain.run(songs=songs_str, user_input=\"I am sad\")\n",
292
+ "res"
 
 
 
 
 
 
 
 
 
 
 
293
  ]
294
  },
295
  {
296
  "cell_type": "code",
297
+ "execution_count": 31,
298
+ "id": "e84eeeaa",
299
  "metadata": {},
300
  "outputs": [],
301
  "source": [
302
+ "import random\n",
303
+ "\n",
304
+ "res = random.choice(eval(res))"
305
  ]
306
  },
307
  {
308
  "cell_type": "code",
309
+ "execution_count": 32,
310
+ "id": "e24ed65f",
 
 
 
 
 
 
 
 
 
311
  "metadata": {},
312
+ "outputs": [
313
+ {
314
+ "name": "stdout",
315
+ "output_type": "stream",
316
+ "text": [
317
+ "frozen;do you want to build a snowman?\n"
318
+ ]
319
+ },
320
+ {
321
+ "data": {
322
+ "text/html": [
323
+ "\n",
324
+ " <iframe\n",
325
+ " width=\"700\"\n",
326
+ " height=\"350\"\n",
327
+ " src=\"https://open.spotify.com/embed/track/2yi7HZrBOC4bMUSTcs4VK6?utm_source=generator\"\n",
328
+ " frameborder=\"0\"\n",
329
+ " allowfullscreen\n",
330
+ " \n",
331
+ " ></iframe>\n",
332
+ " "
333
+ ],
334
+ "text/plain": [
335
+ "<IPython.lib.display.IFrame at 0x7f54178b9d00>"
336
+ ]
337
+ },
338
+ "execution_count": 32,
339
+ "metadata": {},
340
+ "output_type": "execute_result"
341
+ }
342
+ ],
343
  "source": [
344
+ "print(res)\n",
345
+ "doc = movies_and_names_to_songs[res]\n",
346
+ "\n",
347
+ "from IPython.display import IFrame\n",
348
+ "IFrame(doc[\"embed_url\"], width=700, height=350)"
349
  ]
350
  },
351
  {
352
  "cell_type": "code",
353
  "execution_count": null,
354
+ "id": "03de1b93",
355
  "metadata": {},
356
  "outputs": [],
357
+ "source": []
 
 
 
 
 
 
358
  }
359
  ],
360
  "metadata": {