|
import streamlit as st |
|
from transformers import pipeline |
|
|
|
|
|
|
|
st.title("Financial News Sentiment Analysis") |
|
st.write("Identify the sentiment and look into the key point to help you make decisions.") |
|
|
|
|
|
|
|
|
|
pipe = pipeline("text-classification", model="roselyu/FinSent-XLMR-FinNews") |
|
|
|
|
|
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"] |
|
|
|
|
|
if st.button("Identify Sentiment"): |
|
|
|
|
|
|
|
st.write(f"Sentiment: {sentiment_label}") |
|
|
|
|
|
|
|
qa_pipe = pipeline("question-answering", model="Intel/dynamic_tinybert") |
|
|
|
|
|
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?" |
|
|
|
|
|
result = qa_pipe(question=question, context=context)["answer"] |
|
|
|
|
|
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?" |
|
|
|
|
|
if st.button(button_label): |
|
|
|
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}") |
|
|
|
|
|
|