Update app.py
Browse files
app.py
CHANGED
|
@@ -10,14 +10,53 @@ st.write("Summarize long financial news and identify the sentiment to help you m
|
|
| 10 |
pipe = pipeline("text-classification", model="roselyu/FinSent-XLMR-FinNews")
|
| 11 |
|
| 12 |
# User input
|
| 13 |
-
user_input = st.text_area("Enter a financial news article:")
|
| 14 |
|
| 15 |
# Summarize and identify sentiment button
|
| 16 |
-
if st.button("
|
| 17 |
|
| 18 |
# Analyze sentiment
|
| 19 |
sentiment_label = pipe(user_input)[0]["label"]
|
| 20 |
|
| 21 |
# Display summary and sentiment
|
| 22 |
|
| 23 |
-
st.write(f"Sentiment: {sentiment_label}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
pipe = pipeline("text-classification", model="roselyu/FinSent-XLMR-FinNews")
|
| 11 |
|
| 12 |
# User input
|
| 13 |
+
user_input = st.text_area("Enter a short financial news article:")
|
| 14 |
|
| 15 |
# Summarize and identify sentiment button
|
| 16 |
+
if st.button("Identify Sentiment"):
|
| 17 |
|
| 18 |
# Analyze sentiment
|
| 19 |
sentiment_label = pipe(user_input)[0]["label"]
|
| 20 |
|
| 21 |
# Display summary and sentiment
|
| 22 |
|
| 23 |
+
st.write(f"Sentiment: {sentiment_label}")
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
# Initialize the question-answering pipeline
|
| 27 |
+
qa_pipe = pipeline("question-answering", model="deepset/roberta-base-squad2")
|
| 28 |
+
|
| 29 |
+
# Set the context and question based on sentiment
|
| 30 |
+
if sentiment_label == "positive":
|
| 31 |
+
context = user_input
|
| 32 |
+
question = "What's the good news?"
|
| 33 |
+
elif sentiment_label == "negative":
|
| 34 |
+
context = user_input
|
| 35 |
+
question = "What's the issue here?"
|
| 36 |
+
else:
|
| 37 |
+
context = user_input
|
| 38 |
+
question = "What's the opinion?"
|
| 39 |
+
|
| 40 |
+
# Generate the answer
|
| 41 |
+
result = qa_pipe(question=question, context=context)
|
| 42 |
+
|
| 43 |
+
# Display different buttons based on sentiment
|
| 44 |
+
if sentiment_label == "positive":
|
| 45 |
+
button_label = "What's the good news?"
|
| 46 |
+
elif sentiment_label == "negative":
|
| 47 |
+
button_label = "What's the issue here?"
|
| 48 |
+
else:
|
| 49 |
+
button_label = "What's the opinion?"
|
| 50 |
+
|
| 51 |
+
# show the answers
|
| 52 |
+
if st.button(button_label):
|
| 53 |
+
# Callback logic: Display the result based on the button clicked
|
| 54 |
+
if sentiment_label == "positive":
|
| 55 |
+
st.write(f"Here's the good news: {result}")
|
| 56 |
+
elif sentiment_label == "negative":
|
| 57 |
+
st.write(f"The issue is: {result}")
|
| 58 |
+
else:
|
| 59 |
+
st.write(f"The opinion is: {result}")
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
|