File size: 1,808 Bytes
5e62651
10ed7ab
5e62651
bc5a4d3
10ed7ab
 
 
 
 
186083d
10ed7ab
 
 
 
bc5a4d3
 
 
0796587
10ed7ab
bc5a4d3
0796587
10ed7ab
ebc853a
10ed7ab
 
076e629
 
186083d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bc5a4d3
 
 
 
 
 
186083d
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
import streamlit as st
from transformers import pipeline

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

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

    st.set_page_config(page_title="Financial News Analysis", page_icon="♕")

    # Streamlit application layout
    st.title("Financial News Analysis")
    st.write("Analyze corresponding Topic and Trend for Financial News!")
    st.image("./Fin.jpg", use_column_width=True)

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

    analyze_clicked = st.button("Analyze")

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

        # Filter only the news related to "Energy | Oil"
        energy_oil_news = [news for news in results if news["label"] == "Energy | Oil"]
        
        if energy_oil_news:
            # If there are news related to "Energy | Oil", perform sentiment analysis for each news
            for news in energy_oil_news:
                sentiment_results = sentiment_analysis(news["sequence"])[0]

                # Display the sentiment analysis result for each news
                st.write("Original Text:", news["sequence"])
                st.write("Sentiment:", sentiment_results["label"])
                st.write("Sentiment Score:", sentiment_results["score"])
                st.write("---")
        else:
            st.write("No news relevant to Energy | Oil.")

def main():
    analyze_financial_news()

if __name__ == "__main__":
    main()