Spaces:
Runtime error
Runtime error
new version that reccomands three songs and then we take a random one
Browse files- app.py +6 -4
- prompts/bot_with_summary.prompt +6 -5
- 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 |
-
|
70 |
-
|
71 |
-
|
|
|
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 |
-
|
9 |
Input: "Today I am not feeling great"
|
10 |
-
[<MOVIE_NAME>;<SONG_TITLE
|
11 |
Input: "I am great today"
|
12 |
-
[<MOVIE_NAME>;<SONG_TITLE
|
13 |
-
|
|
|
|
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":
|
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": "
|
93 |
"metadata": {},
|
94 |
"source": [
|
95 |
"## Using similarity search"
|
@@ -191,7 +193,7 @@
|
|
191 |
},
|
192 |
{
|
193 |
"cell_type": "markdown",
|
194 |
-
"id": "
|
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":
|
203 |
-
"id": "
|
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=
|
215 |
"\n",
|
216 |
"chain = LLMChain(llm=llm, prompt=prompt)"
|
217 |
]
|
218 |
},
|
219 |
{
|
220 |
"cell_type": "markdown",
|
221 |
-
"id": "
|
222 |
"metadata": {},
|
223 |
"source": [
|
224 |
"Let's create the songs string"
|
@@ -226,8 +231,8 @@
|
|
226 |
},
|
227 |
{
|
228 |
"cell_type": "code",
|
229 |
-
"execution_count":
|
230 |
-
"id": "
|
231 |
"metadata": {},
|
232 |
"outputs": [],
|
233 |
"source": [
|
@@ -239,8 +244,8 @@
|
|
239 |
},
|
240 |
{
|
241 |
"cell_type": "code",
|
242 |
-
"execution_count":
|
243 |
-
"id": "
|
244 |
"metadata": {
|
245 |
"scrolled": true
|
246 |
},
|
@@ -257,78 +262,99 @@
|
|
257 |
},
|
258 |
{
|
259 |
"cell_type": "code",
|
260 |
-
"execution_count":
|
261 |
-
"id": "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
262 |
"metadata": {},
|
263 |
"outputs": [
|
264 |
{
|
265 |
"data": {
|
266 |
"text/plain": [
|
267 |
-
"\"
|
268 |
]
|
269 |
},
|
270 |
-
"execution_count":
|
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":
|
294 |
-
"id": "
|
295 |
"metadata": {},
|
296 |
"outputs": [],
|
297 |
"source": [
|
298 |
-
"
|
|
|
|
|
299 |
]
|
300 |
},
|
301 |
{
|
302 |
"cell_type": "code",
|
303 |
-
"execution_count":
|
304 |
-
"id": "
|
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": "
|
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": {
|