File size: 1,924 Bytes
cf4eeb3
 
 
47ba073
cf4eeb3
951bf5a
47ba073
f69a343
cf4eeb3
 
 
 
 
951bf5a
da1b4ee
86eebf5
 
 
951bf5a
cf4eeb3
 
7681d44
cf4eeb3
 
 
7681d44
 
6726773
7681d44
9af4e17
7681d44
 
 
 
 
 
 
 
 
 
 
 
 
47ba073
7681d44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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}")