File size: 3,724 Bytes
0228682
735a2fd
 
 
 
 
 
 
 
 
df941ba
 
eeeb3ea
df941ba
 
 
 
eeeb3ea
df941ba
 
 
eeeb3ea
df941ba
 
eeeb3ea
df941ba
dd11797
df941ba
 
 
 
 
 
eeeb3ea
df941ba
 
 
 
 
 
eeeb3ea
 
 
 
df941ba
 
 
 
dd11797
 
 
 
 
 
 
0bd503e
dd11797
0bd503e
dd11797
 
df941ba
0bd503e
 
735a2fd
eeeb3ea
dd11797
df941ba
735a2fd
 
0228682
 
df941ba
0228682
 
 
735a2fd
0228682
 
eeeb3ea
0228682
735a2fd
0228682
 
ade49f8
0228682
eeeb3ea
df941ba
0228682
 
 
df941ba
0228682
df941ba
 
0228682
df941ba
 
0228682
eeeb3ea
df941ba
eeeb3ea
df941ba
0228682
df941ba
0228682
df941ba
 
 
0228682
df941ba
0228682
df941ba
0228682
 
 
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import streamlit as st
from func import (
    get_sentiment_pipeline,
    get_ner_pipeline,
    fetch_news,
    analyze_sentiment,
    extract_org_entities,
)
import time

# ----------- Page Config -----------
st.set_page_config(
    page_title="EquiPulse: Real-Time Stock News Sentiment",
    layout="centered",
    initial_sidebar_state="collapsed"
)

# ----------- Custom Styling -----------
st.markdown("""
    <style>
        body {
            background-color: #ffffff;
        }
        h1 {
            color: #002b45;
            font-family: 'Segoe UI', sans-serif;
            font-size: 26px;
        }
        .stTextInput > div > div > input,
        .stTextArea textarea {
            font-size: 16px;
        }
        .stButton>button {
            background-color: #002b45;
            color: white;
            font-size: 16px;
            padding: 0.4rem 1rem;
            border-radius: 6px;
        }
        .stButton>button:hover {
            background-color: #004b78;
        }
        .stMarkdown {
            font-size: 16px;
        }
    </style>
""", unsafe_allow_html=True)

# ----------- Header Section with Icon and Title in One Line -----------
st.markdown("""
    <div style="display: flex; align-items: center; gap: 14px; margin-bottom: 1.5rem;">
        <img src="/mnt/data/e8fea233-2331-4389-8f6d-6f33f097d6ed.png" width="42" height="42">
        <h1 style="margin: 0;">EquiPulse: Real-Time Stock News Sentiment</h1>
    </div>
""", unsafe_allow_html=True)

# ----------- Clean Description Section -----------
st.markdown("""
<div style='font-size:16px; line-height:1.6; color: #333333;'>
    Analyze financial sentiment from real-time news headlines related to your selected companies.
</div>
""", unsafe_allow_html=True)

# ----------- Input Area -----------
st.markdown("#### 🎯 Enter Your Target Company Tickers")
free_text = st.text_area("Example: AAPL, NVDA, NKE", height=90)

ner_pipeline = get_ner_pipeline()
tickers = extract_org_entities(free_text, ner_pipeline)

if tickers:
    st.markdown(f"✅ **Identified Tickers:** `{', '.join(tickers)}`")
else:
    tickers = []

# ----------- Action Button -----------
if st.button("Get News and Sentiment"):
    if not tickers:
        st.warning("⚠️ Please enter at least one recognizable company name.")
    else:
        sentiment_pipeline = get_sentiment_pipeline()
        progress_bar = st.progress(0)
        total_stocks = len(tickers)

        for idx, ticker in enumerate(tickers):
            st.markdown(f"---\n#### 🔍 Analyzing: `{ticker}`")

            news_list = fetch_news(ticker)

            if news_list:
                sentiments = [analyze_sentiment(news['title'], sentiment_pipeline) for news in news_list]

                pos_count = sentiments.count("Positive")
                neg_count = sentiments.count("Negative")
                total = len(sentiments)
                pos_ratio = pos_count / total if total else 0
                neg_ratio = neg_count / total if total else 0

                if pos_ratio >= 0.25:
                    overall = "Positive"
                elif neg_ratio >= 0.75:
                    overall = "Negative"
                else:
                    overall = "Neutral"

                st.markdown(f"**📰 Top News for `{ticker}`:**")
                for i, news in enumerate(news_list[:3]):
                    st.markdown(f"{i+1}. [{news['title']}]({news['link']}) — **{sentiments[i]}**")

                st.success(f"📈 **Overall Sentiment for `{ticker}`: {overall}**")
            else:
                st.info(f"No recent news available for `{ticker}`.")

            progress_bar.progress((idx + 1) / total_stocks)
            time.sleep(0.1)