gouravgujariya commited on
Commit
d30dd77
1 Parent(s): 1cf8000

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -0
app.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import spacy
3
+ from spacytextblob.spacytextblob import SpacyTextBlob
4
+
5
+ st.set_page_config(layout='wide', initial_sidebar_state='expanded')
6
+ st.title('Text Analysis using Spacy Textblob')
7
+ st.markdown('Type a sentence in the below text box and choose the desired option in the adjacent menu.')
8
+ side = st.sidebar.selectbox("Select an option below", ("Sentiment", "Subjectivity", "NER"))
9
+ Text = st.text_input("Enter the sentence")
10
+
11
+
12
+ @st.cache
13
+ def sentiment(text):
14
+ nlp = spacy.load('en_core_web_sm')
15
+ nlp.add_pipe('spacytextblob')
16
+ doc = nlp(text)
17
+ if doc._.polarity<0:
18
+ return "Negative"
19
+ elif doc._.polarity==0:
20
+ return "Neutral"
21
+ else:
22
+ return "Positive"
23
+
24
+
25
+ @st.cache
26
+ def subjectivity(text):
27
+ nlp = spacy.load('en_core_web_sm')
28
+ nlp.add_pipe('spacytextblob')
29
+ doc = nlp(text)
30
+ if doc._.subjectivity > 0.5:
31
+ return "Highly Opinionated sentence"
32
+ elif doc._.subjectivity < 0.5:
33
+ return "Less Opinionated sentence"
34
+ else:
35
+ return "Neutral sentence"
36
+
37
+ @st.cache
38
+ def ner(sentence):
39
+ nlp = spacy.load("en_core_web_sm")
40
+ doc = nlp(sentence)
41
+ ents = [(e.text, e.label_) for e in doc.ents]
42
+ return ents
43
+
44
+
45
+
46
+ def run():
47
+
48
+ if side == "Sentiment":
49
+ st.write(sentiment(Text))
50
+ if side == "Subjectivity":
51
+ st.write(subjectivity(Text))
52
+ if side == "NER":
53
+ st.write(ner(Text))
54
+
55
+
56
+
57
+ if __name__ == '__main__':
58
+ run()
59
+