File size: 4,658 Bytes
6dba858
88055ae
 
f521496
6dba858
f521496
88055ae
cb68822
867f7a1
09bef43
 
 
 
 
 
bd8cf8c
88055ae
2ecd65e
88055ae
1cd7ed4
6dba858
cb68822
f92543a
 
d294c45
f4ca8de
d2ac7fa
 
 
 
 
 
 
 
 
 
 
f92543a
 
d2ac7fa
6b072bf
d2ac7fa
 
 
 
6b072bf
d2ac7fa
9e4371a
d2ac7fa
 
 
 
 
 
4e58636
6b072bf
ebd9c21
 
 
 
318df58
 
9600adb
0030bab
2392586
318df58
0030bab
318df58
2ada429
4958d02
 
060b6bc
 
2ada429
b72dcc3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
060b6bc
9bc5e9e
4854d0b
d7857b3
68de716
88055ae
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import streamlit.components.v1 as components
from streamlit_player import st_player
from transformers import pipeline
from tabulate import tabulate
import streamlit as st



st.header("stream your emotions")
st.caption("LOVE: i love you")
st.caption("SURPRISE: shocking")
st.caption("SADNESS: i feel exhausted")
st.caption("JOY: bro i feel so energetic")
st.caption("FEAR: im scared of what lies ahead")
st.caption("ANGER: you piss me off")

def tester(text):
  classifier = pipeline("sentiment-analysis", model='bhadresh-savani/distilbert-base-uncased-emotion')
  results = classifier(text)
  #st.subheader(results[0]['label'])

#tester(emo)
  generator = st.button("Generate Song!")
  if (generator == True):
    st.subheader(results[0]['label'])
  
    if (results[0]['label']=="joy"): #songs for joy emotion
      with open('joyplaylist.txt') as f:
        contents = f.read()
      components.html(contents,width=560,height=325)
    
    elif (results[0]['label']=="fear"):
      with open('fearplaylist.txt') as f:
        contents = f.read()
      components.html(contents,width=560,height=325)
    
    elif (results[0]['label']=="anger"): #songs for anger emotion
      with open('angryplaylist.txt') as f:
        contents = f.read()
      components.html(contents,width=560,height=325)    

    elif (results[0]['label']=="sadness"): #songs for sadness emotion
      with open('sadplaylist.txt') as f:
        contents = f.read()
      components.html(contents,width=560,height=325)

    elif (results[0]['label']=="surprise"):
      components.html("""<iframe width="560" height="315" src="https://www.youtube.com/embed/dQw4w9WgXcQ?autoplay=1" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>""",width=560,height=325)

    elif (results[0]['label']=="love"):
      with open('loveplaylist.txt') as f:
        contents = f.read()
      components.html(contents,width=560,height=325)
 
emo = st.text_input("Enter a text/phrase/sentence. A corresponding song will be recommended based on its emotion.")


st.sidebar.subheader("Description")
st.sidebar.write("This application detects the emotion behind your text input and recommends a song that matches it.")

st.sidebar.subheader("Disclaimer/Limitations")
st.sidebar.write("The model only outputs sadness, joy, love, anger, fear, and surprise. With that said, it does not completely encompass the emotions that a human being feels, and the application only suggests a playlist based on the aforementioned emotions.")

st.sidebar.subheader("Model Description")
st.sidebar.write("This application uses the DistilBERT model, a distilled version of BERT. The BERT framework uses a bidirectional transformer that allows it to learn the context of a word based on the left and right of the word. According to a paper by V. Sanh, et al., DistilBERT can \"reduce the size of a BERT model by 40%, while retaining 97% of its language understanding capabilities, and being 60% faster.\" This is why the DistilBERT model was used. For more information about the paper, please check out this [link](https://arxiv.org/abs/1910.01108).")
st.sidebar.write("The specific DistilBERT model used for this is Bhadresh Savani's [distilbert-base-uncased-emotion] (https://huggingface.co/bhadresh-savani/distilbert-base-uncased-emotion). It is fine-tuned on the Emotion Dataset from Twitter, which can be found [here](https://huggingface.co/datasets/viewer/?dataset=emotion).")

st.sidebar.subheader("Performance Benchmarks")
st.sidebar.write("[Distilbert-base-uncased-emotion](https://huggingface.co/bhadresh-savani/distilbert-base-uncased-emotion)")
st.sidebar.write("Accuracy = 93.8")
st.sidebar.write("F1 Score = 93.79")
st.sidebar.write("Test Sample per Second = 398.69")

st.sidebar.write("[Bert-base-uncased-emotion](https://huggingface.co/bhadresh-savani/bert-base-uncased-emotion)")
st.sidebar.write("Accuracy = 94.05")
st.sidebar.write("F1 Score = 94.06")
st.sidebar.write("Test Sample per Second = 190.152")

st.sidebar.write("[Roberta-base-emotion](https://huggingface.co/bhadresh-savani/roberta-base-emotion)")
st.sidebar.write("Accuracy = 93.95")
st.sidebar.write("F1 Score = 93.97")
st.sidebar.write("Test Sample per Second = 195.639")

st.sidebar.write("[Albert-base-v2-emotion](https://huggingface.co/bhadresh-savani/albert-base-v2-emotion)")
st.sidebar.write("Accuracy = 93.6")
st.sidebar.write("F1 Score = 93.65")
st.sidebar.write("Test Sample per Second = 182.794")




tester(emo)