shawarmabytes's picture
Update app.py
6f7c56d
raw history blame
No virus
1.96 kB
import streamlit.components.v1 as components
from streamlit_player import st_player
from transformers import pipeline
import streamlit as st
import random
def tester(text):
classifier = pipeline("sentiment-analysis", model='bhadresh-savani/distilbert-base-uncased-emotion')
results = classifier(text)
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)
contents.close()
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)
contents.close()
elif (results[0]['label']=="disgust"):
st_player("https://www.youtube.com/watch?v=zWq2TT3ieGE")
elif (results[0]['label']=="fear"):
with open('fearplaylist.txt') as f:
contents = f.read()
components.html(contents,width=560,height=325)
contents.close()
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)
contents.close()
elif (results[0]['label']=="surprise"):
st.write("gulat ka noh")
elif (results[0]['label']=="love"):
with open('loveplaylist.txt') as f:
contents = f.read()
components.html(contents,width=560,height=325)
contents.close()
return results[0]['label']
st.header("stream your emotions")
#st.write("Enter a text/phrase/sentence. A corresponding song will be recommended based on its emotion")
emo = st.text_input("Enter a text/phrase/sentence. A corresponding song will be recommended based on its emotion.")
st.write("Examples: i love you so much")
st.write("I am exhausted.")
st.write("I feel energetic.")
st.write("bro you scared me there")
tester(emo)