VISION23 commited on
Commit
f1b4543
ยท
verified ยท
1 Parent(s): 3ad630d

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +77 -0
app.py ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import streamlit as st
3
+ import pandas as pd
4
+ import numpy as np
5
+ import altair as alt
6
+ import joblib
7
+ import webbrowser
8
+
9
+ pipe_lr = joblib.load(open("D:/BEEBOX/visionott/scri.pkl", "rb"))
10
+
11
+ emotions_emoji_dict = {"anger": "๐Ÿ˜ ", "disgust": "๐Ÿคฎ", "fear": "๐Ÿ˜จ๐Ÿ˜ฑ", "happy": "๐Ÿค—", "joy": "๐Ÿ˜‚", "neutral": "๐Ÿ˜", "sad": "๐Ÿ˜”",
12
+ "sadness": "๐Ÿ˜”", "shame": "๐Ÿ˜ณ", "surprise": "๐Ÿ˜ฎ"}
13
+
14
+
15
+ def predict_emotions(docx):
16
+ results = pipe_lr.predict([docx])
17
+ return results[0]
18
+
19
+
20
+ def get_prediction_proba(docx):
21
+ results = pipe_lr.predict_proba([docx])
22
+ return results
23
+
24
+
25
+ def main():
26
+ st.title("How was your Day Dude ? ๐Ÿค” ")
27
+ st.subheader("Detect Emotions In Text and Recommend Movies")
28
+
29
+
30
+
31
+ with st.form(key='my_form'):
32
+ raw_text = st.text_area("Type Here")
33
+ submit_text = st.form_submit_button(label='Submit')
34
+
35
+
36
+
37
+ if submit_text:
38
+ col1, col2 = st.columns(2)
39
+
40
+ prediction = predict_emotions(raw_text)
41
+ probability = get_prediction_proba(raw_text)
42
+
43
+ emotion = prediction
44
+ youtube_link = f"https://www.youtube.com/results?search_query={emotion}+movie"
45
+ st.info(f"Recommended movies for {emotion}:")
46
+ st.write(youtube_link)
47
+ if st.button("Open YouTube"):
48
+ webbrowser.open(youtube_link)
49
+
50
+ with col1:
51
+ st.success("Original Text")
52
+ st.write(raw_text)
53
+
54
+ st.success("Prediction")
55
+ emoji_icon = emotions_emoji_dict[prediction]
56
+ st.write("{}:{}".format(prediction, emoji_icon))
57
+ st.write("Confidence:{}".format(np.max(probability)))
58
+
59
+ with col2:
60
+ st.success("Prediction Probability")
61
+ proba_df = pd.DataFrame(probability, columns=pipe_lr.classes_)
62
+ proba_df_clean = proba_df.T.reset_index()
63
+ proba_df_clean.columns = ["emotions", "probability"]
64
+
65
+ fig = alt.Chart(proba_df_clean).mark_bar().encode(x='emotions', y='probability', color='emotions')
66
+ st.altair_chart(fig, use_container_width=True)
67
+
68
+
69
+
70
+
71
+
72
+
73
+
74
+
75
+
76
+ if __name__ == '__main__':
77
+ main()