from dotenv import load_dotenv load_dotenv(dotenv_path="../env_vars.env") import json from pathlib import Path import os from langchain.chains import LLMChain from langchain.chat_models import ChatOpenAI from langchain.embeddings.openai import OpenAIEmbeddings from langchain.prompts import PromptTemplate from langchain.vectorstores import DeepLake from utils import clean_emotions_json """ This function takes all the songs we have and use the lyrics to create a list of 8 emotions. These 8 emotions will then be used for similarity matching with user prompt emotions, instead of using the entire lyrics. """ def generate_emotion_from_lyrics(input_file:str, prompt_path:str, output_file:str, clean_output=True) -> None: prompt = PromptTemplate( input_variables=["song_lyrics"], template=Path(prompt_path).read_text(), ) llm = ChatOpenAI(temperature=0.8) chain = LLMChain(llm=llm, prompt=prompt) # Read file that has scraped lyrics. with open(input_file, "r") as f: lyrical_data = json.load(f) ''' 'song' looks like as follows { "song_name": "Cruel Summer", "iframe": "