File size: 1,624 Bytes
7c2ff9d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
from transformers import pipeline
import time

def sentiment(summary):
    pipe = pipeline("text-classification", model="WillWEI0103/CustomModel_finance_sentiment_analytics")
    label = pipe(summary)[0]['label']
    score = pipe(summary)[0]['score']
    return label,score


def main():
    dicts={"bullish":'Positive📈',"bearish":'Negative📉','neutral':"Neutral😐"}
    st.header("Summarize Your Finance News and Analyze Sentiment📰")
    text=st.text_input('Input your Finance news(Max lenth<=3000): ',None,max_chars=3000)
    #if text is not None:
    if st.button('Conduct'):
        st.text_area('Your Finance News: ',text,height=100)

        #Stage 1: Text Summarization
        with st.status("Processing Finance News Summarization...") as status:
            text_summarize=pipeline("summarization", model="nickmuchi/fb-bart-large-finetuned-trade-the-event-finance-summarizer")
            summary=text_summarize(text)[0]['summary_text']
            status.update(label="Summarization Completed", state="complete", expanded=False)
        st.text_area('Your Finance News Summary',summary,height=30)

        #Stage 2: Sentiment Analytics
        with st.status("Processing Sentiment Analytics..") as status:
            label,score = sentiment(summary)
            label=dicts[label]
            status.update(label="Sentiment Analytics Completed", state="complete", expanded=False)
        st.text('The Sentiment of the Finance News is: ')
        st.text(label)
        st.text('The Sentiment Score: ')
        st.text(round(score,3))
        
if __name__ == "__main__":
    main()