import streamlit as st from transformers import pipeline # Streamlit application title st.title("Financial News Sentiment Analysis") st.write("Identify the sentiment and look into the key point to help you make decisions.") # Load the summarization and sentiment analysis pipelines pipe = pipeline("text-classification", model="roselyu/FinSent-XLMR-FinNews") # User input and sentiment analysis default_summary = "Enter a financial news summary here." user_input = st.text_area("Enter a short financial news article to identify its sentiments:", value=default_summary) sentiment_label = pipe(user_input)[0]["label"] # Summarize and identify sentiment button if st.button("Identify Sentiment"): # Display summary and sentiment st.write(f"Sentiment: {sentiment_label}") # Initialize the question-answering pipeline qa_pipe = pipeline("question-answering", model="Intel/dynamic_tinybert") # Set the context and question based on sentiment if sentiment_label == "positive": context = user_input question = "What's the good news?" elif sentiment_label == "negative": context = user_input question = "What's the issue here?" else: context = user_input question = "What's the opinion?" # Generate the answer result = qa_pipe(question=question, context=context)["answer"] # Display different buttons based on sentiment if sentiment_label == "positive": button_label = "What's the good news?" elif sentiment_label == "negative": button_label = "What's the issue here?" else: button_label = "What's the opinion?" # show the answers if st.button(button_label): # Callback logic: Display the result based on the button clicked if sentiment_label == "positive": st.write(f"Here's the good news: {result}") elif sentiment_label == "negative": st.write(f"The issue is: {result}") else: st.write(f"The opinion is: {result}")