File size: 1,113 Bytes
2a6cb96
 
 
 
e997328
 
db2d292
 
e997328
 
db2d292
e997328
 
db2d292
 
 
 
e997328
 
 
 
 
 
 
 
 
db2d292
2a6cb96
db2d292
 
e997328
 
 
 
 
 
 
db2d292
 
 
 
 
 
 
2a6cb96
db2d292
 
e997328
 
db2d292
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
"""
This script takes all the songs we have and create a summary for each lyric
"""

from dotenv import load_dotenv

load_dotenv()

import json
from collections import defaultdict
from pathlib import Path
from pprint import pprint

from langchain.chains import LLMChain
from langchain.chat_models import ChatOpenAI
from langchain.prompts import PromptTemplate

prompt = PromptTemplate(
    input_variables=["song"],
    template=Path("prompts/summary.prompt").read_text(),
)

llm = ChatOpenAI(temperature=0)

chain = LLMChain(llm=llm, prompt=prompt)

with open(
    "data/lyrics_with_spotify_url.json",
    "r",
) as f:
    data = json.load(f)

lyrics_summaries = {}

for movie, lyrics in data.items():
    for lyric in lyrics:
        print(f"Creating summary for {lyric['name']}")
        summary = chain.run(song=lyric["text"])
        lyrics_summaries[lyric["name"].lower()] = {
            "summary": summary,
            "embed_url": lyric["embed_url"],
        }

with open(
    "data/lyrics_with_spotify_url_and_summary.json",
    "w",
) as f:
    json.dump(lyrics_summaries, f)

pprint(lyrics_summaries)