File size: 1,217 Bytes
ef00845
 
 
 
8f0b4f6
 
 
 
 
 
 
 
 
ef00845
 
5287e89
ef00845
 
 
 
 
 
 
 
 
 
5f1735b
8f0b4f6
 
ef00845
 
 
 
 
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
import streamlit as st
from transformers import pipeline

sentiment_analysis = pipeline("sentiment-analysis", model="nlptown/bert-base-multilingual-uncased-sentiment")

def convert_label_to_sentiment(label):
    if label in ["4", "5"]:
        return "Positive"
    elif label in ["1", "2"]:
        return "Negative"
    else:
        return "Neutral"

def perform_sentiment_analysis(text):
    result = sentiment_analysis(text)
    return {'label': result[0]['label'], 'score': result[0]['score']}

def main():
    st.title("Financial Sentiment Analysis")

    # Input for financial content
    financial_content = st.text_area("Enter Financial Content:", "With the launch of Apple Silicon, Apple shares have increased")

    # Perform sentiment analysis on button click
    if st.button("Submit"):
        if financial_content.strip():
            sentiment_result = perform_sentiment_analysis(financial_content)
            sentiment = convert_label_to_sentiment(sentiment_result['label'][0])
            st.success(f"Sentiment: {sentiment} | Score: {sentiment_result['score']:.2f}")
        else:
            st.warning("Please enter financial content before submitting.")

if __name__ == "__main__":
    main()