File size: 2,161 Bytes
e997328
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9b3dd41
e997328
 
 
9b3dd41
 
 
 
 
 
 
 
 
 
 
 
 
e997328
 
9b3dd41
 
e997328
 
 
 
 
 
9b3dd41
e997328
9b3dd41
e997328
 
 
 
 
 
 
 
 
 
 
 
 
9b3dd41
 
 
 
 
 
 
e997328
9b3dd41
 
e997328
9b3dd41
e997328
 
 
 
 
 
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
from pathlib import Path

import streamlit as st
from dotenv import load_dotenv
from langchain.chains import LLMChain
from langchain.prompts import PromptTemplate

load_dotenv()
import os

from langchain.chat_models import ChatOpenAI
from langchain.embeddings.openai import OpenAIEmbeddings

from data import load_db
from names import DATASET_ID, MODEL_ID
import json 

@st.cache_resource
def init():
    # embeddings = OpenAIEmbeddings(model=MODEL_ID)
    # dataset_path = f"hub://{os.environ['ACTIVELOOP_ORG_ID']}/{DATASET_ID}"

    # db = load_db(
    #     dataset_path,
    #     embedding_function=embeddings,
    #     token=os.environ["ACTIVELOOP_TOKEN"],
    #     org_id=os.environ["ACTIVELOOP_ORG_ID"],
    #     read_only=True,
    # )

    with open("/home/zuppif/Documents/Work/ActiveLoop/ai-shazam/data/lyrics_with_spotify_url_and_summary.json", "r") as f:
        songs = json.load(f)

    prompt = PromptTemplate(
        input_variables=["songs", "user_input"],
        template=Path("prompts/bot_with_summary.prompt").read_text(),
    )

    llm = ChatOpenAI(temperature=0.7)

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

    return chain, songs, json.dumps(songs)

chain, songs, songs_json = init()

st.title("Disney song for you")

text_input = st.text_input(
    label="How are you feeling today?",
    placeholder="I am ready to rock and rool!",
)

clicked = st.button("Click me")
placeholder_emotions = st.empty()
placeholder = st.empty()

def get_emotions(user_input):
    song_name = chain.run(songs=songs_json, user_input=user_input)
    song_name.replace('\'', '')
    print(f"Song: {song_name}")
    song = songs[song_name.lower()]
    # matches = db.similarity_search_with_score(emotions, distance_metric="cos")
    # print(matches)
    # doc, score = matches[0]
    iframes_html = ""
    # with placeholder_emotions:
    #     st.write(emotions)
    with placeholder:
        embed_url = song["embed_url"]
        iframe_html = f'<iframe src="{embed_url}" style="border:0"> </iframe>'
        st.components.v1.html(f"<div style='display:flex;flex-direction:column'>{iframe_html}</div>")


if clicked:
    get_emotions(text_input)