forked from valeriialeskina/IamHere
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstreamlit_freetext.py
91 lines (48 loc) · 1.76 KB
/
streamlit_freetext.py
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
#!/usr/bin/env python
# coding: utf-8
# In[5]:
from mpl_toolkits.mplot3d import Axes3D
#from sklearn.preprocessing import StandardScaler
import matplotlib.pyplot as plt # plotting
import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
from nrclex import NRCLex
from matplotlib.font_manager import FontProperties
import streamlit as st
import plotly.express as px
from plotly.subplots import make_subplots
from textblob import TextBlob
from wordcloud import WordCloud, STOPWORDS
# In[6]:
def calcu1 (x):
text_object = NRCLex(x)
matches = text_object.affect_frequencies
return (matches)
abc = 'I am walking in the forest. I just saw a lion. I was scared and surprised. I was not sure what to do'
if st.subheader("Write down your thoughts"):
message = st.text_area("Enter Text",abc)
if st.button("Submit"):
col1,col2 =st.beta_columns(2)
with col1:
st.subheader('Frequency of your emotions')
blob = calcu1(message)
data_items = blob.items()
data_list = list(data_items)
df = pd.DataFrame(data_list,columns = ['Emotion','value'])
df1= df[df['value'] != 0]
a_list = df1['Emotion'].tolist()
fig = px.pie(df1, values= df1.value,names= a_list)
st.plotly_chart(fig,use_container_width=True)
with col2:
st.subheader('Top words used in the text')
wordcloud2 = WordCloud(background_color='white',width=400, height=200).generate(message)
st.set_option('deprecation.showPyplotGlobalUse', False)
plt.imshow(wordcloud2)
plt.axis("off")
st.pyplot()
# In[7]:
# In[ ]:
# In[ ]:
# In[ ]:
# In[ ]:
# In[ ]: