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()