Spaces:
Runtime error
Runtime error
archiagrawal
commited on
Commit
•
8f0b4f6
1
Parent(s):
ae4ee2f
Update app.py
Browse files
app.py
CHANGED
@@ -2,6 +2,15 @@ import streamlit as st
|
|
2 |
from transformers import pipeline
|
3 |
|
4 |
sentiment_analysis = pipeline("sentiment-analysis", model="nlptown/bert-base-multilingual-uncased-sentiment")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
def perform_sentiment_analysis(text):
|
6 |
result = sentiment_analysis(text)
|
7 |
return {'label': result[0]['label'], 'score': result[0]['score']}
|
@@ -14,15 +23,10 @@ def main():
|
|
14 |
|
15 |
# Perform sentiment analysis on button click
|
16 |
if st.button("Submit"):
|
17 |
-
sentiment="Neutral "
|
18 |
if financial_content.strip():
|
19 |
sentiment_result = perform_sentiment_analysis(financial_content)
|
20 |
-
|
21 |
-
|
22 |
-
sentiment= "Positive"
|
23 |
-
elif sentiment_result['label'][0]=="1" or sentiment_result['label'][0]=="2" :
|
24 |
-
sentiment= "Negative"
|
25 |
-
st.success(f"Sentiment: {sentiment} Score: {sentiment_result['score']:.2f}")
|
26 |
else:
|
27 |
st.warning("Please enter financial content before submitting.")
|
28 |
|
|
|
2 |
from transformers import pipeline
|
3 |
|
4 |
sentiment_analysis = pipeline("sentiment-analysis", model="nlptown/bert-base-multilingual-uncased-sentiment")
|
5 |
+
|
6 |
+
def convert_label_to_sentiment(label):
|
7 |
+
if label in ["4", "5"]:
|
8 |
+
return "Positive"
|
9 |
+
elif label in ["1", "2"]:
|
10 |
+
return "Negative"
|
11 |
+
else:
|
12 |
+
return "Neutral"
|
13 |
+
|
14 |
def perform_sentiment_analysis(text):
|
15 |
result = sentiment_analysis(text)
|
16 |
return {'label': result[0]['label'], 'score': result[0]['score']}
|
|
|
23 |
|
24 |
# Perform sentiment analysis on button click
|
25 |
if st.button("Submit"):
|
|
|
26 |
if financial_content.strip():
|
27 |
sentiment_result = perform_sentiment_analysis(financial_content)
|
28 |
+
sentiment = convert_label_to_sentiment(sentiment_result['label'][0])
|
29 |
+
st.success(f"Sentiment: {sentiment} | Score: {sentiment_result['score']:.2f}")
|
|
|
|
|
|
|
|
|
30 |
else:
|
31 |
st.warning("Please enter financial content before submitting.")
|
32 |
|