File size: 1,921 Bytes
0d35448
 
 
 
 
 
 
 
 
c901c38
0d35448
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
from transformers import pipeline

def analyze_financial_news():
    access = "hf_"
    token = "hhbFNpjKohezoexWMlyPUpvJQLWlaFhJaa"

    # Load the text classification model and finetuned model pipeline
    classification = pipeline("text-classification", model="nickmuchi/finbert-tone-finetuned-finance-topic-classification", token=access+token)
    sentiment_analysis = pipeline("text-classification", model="ZephyruSalsify/FinNews_SentimentAnalysis_v3")

    st.set_page_config(page_title="Energy/Oil-Related Financial News Sentiment Analysis", page_icon="♕")

    # Streamlit application layout
    st.title("Energy/Oil-Related Financial News Sentiment Analysis")
    st.write("Conduct Sentiment Analysis for Energy/Oil-Related Financial News to Find Out the Trend In Energy/Oil Industry and Make Wise Decisions!")
    st.image("./Fin.jpg", use_column_width=True)

    # Text input for user to enter the text
    text = st.text_area("Enter the Financial News Content", "")

    analyze_clicked = st.button("Analyze")

    if analyze_clicked:
        # Perform text classification on the input text
        results = classification(text)[0]

        # Check if the classification is "Energy | Oil"
        if results["label"] == "Energy | Oil":
            # If the news is related to Energy | Oil, perform sentiment analysis
            sentiment_results = sentiment_analysis(text)[0]
            
            # Display the sentiment analysis result
            st.write("This financial news belongs to the 'Energy | Oil' category.")
            st.write("Sentiment:", sentiment_results["label"])
            st.write("Sentiment Score:", sentiment_results["score"])
        else:
            st.write("This financial news does not belong to the 'Energy | Oil' category. Please enter a relevant news article.")

def main():
    analyze_financial_news()

if __name__ == "__main__":
    main()