Kovila
commited on
Commit
·
bbfab4a
1
Parent(s):
dce354b
sentiment analysis
Browse files
app.py
CHANGED
@@ -3,6 +3,8 @@ import toml
|
|
3 |
import finnhub
|
4 |
import datetime
|
5 |
from transformers import pipeline
|
|
|
|
|
6 |
import streamlit as st
|
7 |
|
8 |
|
@@ -54,9 +56,29 @@ def get_news_summary(news):
|
|
54 |
news_summary = SUMMARIZER(news)
|
55 |
return news_summary[0]['summary_text']
|
56 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
# APP
|
58 |
-
st.title('Financial News Summarization and Sentiment')
|
59 |
-
st.write('Enter the stock ticker and period for which you want financial news.')
|
60 |
stock_ticker = st.text_input('Stock Ticker:', 'AAPL')
|
61 |
start_date = st.date_input('Start Date:', datetime.datetime.today()-datetime.timedelta(days=20))
|
62 |
end_date = st.date_input('End Date:', datetime.datetime.today())
|
@@ -64,6 +86,9 @@ news = financial_news(stock_ticker, start_date, end_date)
|
|
64 |
st.write(news)
|
65 |
|
66 |
st.header('Financial News Sentiment')
|
|
|
|
|
|
|
67 |
|
68 |
st.header('Financial News Summary')
|
69 |
with st.spinner('facebook bart model is summarizing the news...'):
|
|
|
3 |
import finnhub
|
4 |
import datetime
|
5 |
from transformers import pipeline
|
6 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
7 |
+
import torch
|
8 |
import streamlit as st
|
9 |
|
10 |
|
|
|
56 |
news_summary = SUMMARIZER(news)
|
57 |
return news_summary[0]['summary_text']
|
58 |
|
59 |
+
# get financial news sentiment
|
60 |
+
@st.cache_resource
|
61 |
+
def load_tokenizer():
|
62 |
+
return AutoTokenizer.from_pretrained("ProsusAI/finbert")
|
63 |
+
|
64 |
+
@st.cache_resource
|
65 |
+
def load_sentiment_classification_model():
|
66 |
+
return AutoModelForSequenceClassification.from_pretrained("ProsusAI/finbert")
|
67 |
+
|
68 |
+
FINBERT_TOKENIZER = load_tokenizer()
|
69 |
+
FINBERT_CLASSIFIER = load_sentiment_classification_model()
|
70 |
+
|
71 |
+
def get_news_sentiment(news):
|
72 |
+
news = news.replace('\n\n', ' ')
|
73 |
+
inputs = FINBERT_TOKENIZER([news.replace('\n\n', '')], padding = True, truncation = True, return_tensors='pt')
|
74 |
+
outputs = FINBERT_CLASSIFIER(**inputs)
|
75 |
+
predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)
|
76 |
+
postive, neutral, negative = tuple(predictions.tolist()[0])
|
77 |
+
return postive, neutral, negative
|
78 |
+
|
79 |
# APP
|
80 |
+
st.title('Financial News Headlines Summarization and Sentiment')
|
81 |
+
st.write('Enter the stock ticker and period for which you want financial news headlines.')
|
82 |
stock_ticker = st.text_input('Stock Ticker:', 'AAPL')
|
83 |
start_date = st.date_input('Start Date:', datetime.datetime.today()-datetime.timedelta(days=20))
|
84 |
end_date = st.date_input('End Date:', datetime.datetime.today())
|
|
|
86 |
st.write(news)
|
87 |
|
88 |
st.header('Financial News Sentiment')
|
89 |
+
with st.spinner('facebook bart model is summarizing the news...'):
|
90 |
+
postive, neutral, negative = get_news_sentiment(news)
|
91 |
+
st.bar_chart(x=['positive', 'neutral', 'negative'], y=[postive, neutral, negative], color=[0,1,2])
|
92 |
|
93 |
st.header('Financial News Summary')
|
94 |
with st.spinner('facebook bart model is summarizing the news...'):
|