File size: 2,077 Bytes
f1b4543
 
 
 
 
 
 
 
103e653
f1b4543
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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

import streamlit as st
import pandas as pd
import numpy as np
import altair as alt
import joblib
import webbrowser

pipe_lr = joblib.load(open("scri.pkl", "rb"))

emotions_emoji_dict = {"anger": "๐Ÿ˜ ", "disgust": "๐Ÿคฎ", "fear": "๐Ÿ˜จ๐Ÿ˜ฑ", "happy": "๐Ÿค—", "joy": "๐Ÿ˜‚", "neutral": "๐Ÿ˜", "sad": "๐Ÿ˜”",
                       "sadness": "๐Ÿ˜”", "shame": "๐Ÿ˜ณ", "surprise": "๐Ÿ˜ฎ"}


def predict_emotions(docx):
    results = pipe_lr.predict([docx])
    return results[0]


def get_prediction_proba(docx):
    results = pipe_lr.predict_proba([docx])
    return results


def main():
    st.title("How was your Day Dude ? ๐Ÿค” ")
    st.subheader("Detect Emotions In Text and Recommend Movies")



    with st.form(key='my_form'):
        raw_text = st.text_area("Type Here")
        submit_text = st.form_submit_button(label='Submit')



    if submit_text:
        col1, col2 = st.columns(2)

        prediction = predict_emotions(raw_text)
        probability = get_prediction_proba(raw_text)

        emotion = prediction
        youtube_link = f"https://www.youtube.com/results?search_query={emotion}+movie"
        st.info(f"Recommended movies for {emotion}:")
        st.write(youtube_link)
        if st.button("Open YouTube"):
            webbrowser.open(youtube_link)

        with col1:
            st.success("Original Text")
            st.write(raw_text)

            st.success("Prediction")
            emoji_icon = emotions_emoji_dict[prediction]
            st.write("{}:{}".format(prediction, emoji_icon))
            st.write("Confidence:{}".format(np.max(probability)))

        with col2:
            st.success("Prediction Probability")
            proba_df = pd.DataFrame(probability, columns=pipe_lr.classes_)
            proba_df_clean = proba_df.T.reset_index()
            proba_df_clean.columns = ["emotions", "probability"]

            fig = alt.Chart(proba_df_clean).mark_bar().encode(x='emotions', y='probability', color='emotions')
            st.altair_chart(fig, use_container_width=True)









if __name__ == '__main__':
    main()