-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
56 lines (48 loc) · 1.82 KB
/
main.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
import pandas as pd
import spacy
from textblob import TextBlob
import utils
import warnings
import streamlit as st
warnings.filterwarnings("ignore")
nlp = spacy.load('en_core_web_md')
option=st.selectbox(
'Choose the website',
('Economic Times', 'CNBC', 'Hindustan Business'))
url= st.text_input("Enter the url")
if url:
#url ="https://economictimes.indiatimes.com/markets/stocks/news/oil-prices-rise-on-supply-deficit-concerns/articleshow/103770779.cms?from=mdr"
text = utils.get_article(option,url)
# clean the text
clean_text= text.replace("/n", " ")
clean_text= clean_text.replace("/", " ")
clean_text= ''.join([c for c in clean_text if c != "'"])
#split the article into sentences
sentence=[]
tokens = nlp(clean_text)
for sent in tokens.sents:
sentence.append((sent.text.strip()))
# get the sentiment for each sentence
textblob_sentiment=[]
for s in sentence:
txt= TextBlob(s)
a= txt.sentiment.polarity
b= txt.sentiment.subjectivity
textblob_sentiment.append([s,a,b])
# created df of sentence and sentiments
df_textblob = pd.DataFrame(textblob_sentiment, columns =['Sentence', 'Polarity', 'Subjectivity'])
# added keywords of each sentence
df_textblob['Keywords']= df_textblob['Sentence'].apply(lambda x : utils.get_keywords(x))
#display df on streamlit
st.dataframe(df_textblob)
#display plots on streamlit
utils.plots(df_textblob)
summ_text= utils.summarizer(text)
#to display summary on streamlit
st.write("Summary of the news article")
st.write(summ_text)
txt= TextBlob(summ_text)
#sentiment analysis of summary
st.write("Sentiment Analysis of the summarized text")
st.write("Polarity : "+ str(txt.sentiment.polarity))
#print(txt.sentiment.polarity)