roselyu's picture
Update app.py
1d20147 verified
raw
history blame
1.87 kB
import streamlit as st
from transformers import pipeline
# Streamlit application title
st.title("Financial News Sentiment Analysis")
st.write("Identify the sentiment 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
user_input = st.text_area("Enter a short financial news article:")
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}")
# set initial values
sentiment_label = 0
context = 0
question = 0
# Initialize the question-answering pipeline
qa_pipe = pipeline("question-answering", model="deepset/roberta-base-squad2")
# 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)[0]["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}")