Update app.py
Browse files
app.py
CHANGED
@@ -21,10 +21,25 @@ st.markdown("""
|
|
21 |
body {
|
22 |
background-color: #ffffff;
|
23 |
}
|
24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
color: #002b45;
|
26 |
font-family: 'Segoe UI', sans-serif;
|
27 |
-
font-size:
|
|
|
|
|
28 |
}
|
29 |
.stTextInput > div > div > input,
|
30 |
.stTextArea textarea {
|
@@ -46,50 +61,49 @@ st.markdown("""
|
|
46 |
</style>
|
47 |
""", unsafe_allow_html=True)
|
48 |
|
49 |
-
# ----------- Header
|
50 |
st.markdown("""
|
51 |
-
<div
|
52 |
-
<h1
|
53 |
</div>
|
54 |
""", unsafe_allow_html=True)
|
55 |
|
56 |
-
|
57 |
-
# ----------- Clean Description Section -----------
|
58 |
st.markdown("""
|
59 |
-
<div style='font-size:16px; line-height:1.6; color: #333333;'>
|
60 |
-
Analyze financial sentiment from
|
61 |
</div>
|
62 |
""", unsafe_allow_html=True)
|
63 |
|
64 |
# ----------- Input Area -----------
|
65 |
-
st.markdown("#### π― Enter
|
66 |
-
free_text = st.text_area("Example: AAPL,
|
67 |
|
|
|
68 |
ner_pipeline = get_ner_pipeline()
|
69 |
tickers = extract_org_entities(free_text, ner_pipeline)
|
70 |
|
71 |
if tickers:
|
72 |
-
st.markdown(f"β
**
|
73 |
else:
|
74 |
tickers = []
|
75 |
|
76 |
# ----------- Action Button -----------
|
77 |
-
if st.button("Get News and Sentiment"):
|
78 |
if not tickers:
|
79 |
-
st.warning("β οΈ Please enter at least one recognizable company name.")
|
80 |
else:
|
81 |
sentiment_pipeline = get_sentiment_pipeline()
|
82 |
progress_bar = st.progress(0)
|
83 |
total_stocks = len(tickers)
|
84 |
|
85 |
for idx, ticker in enumerate(tickers):
|
86 |
-
st.markdown(f"---\n#### π Analyzing
|
87 |
|
88 |
news_list = fetch_news(ticker)
|
89 |
|
90 |
if news_list:
|
91 |
sentiments = [analyze_sentiment(news['title'], sentiment_pipeline) for news in news_list]
|
92 |
-
|
93 |
pos_count = sentiments.count("Positive")
|
94 |
neg_count = sentiments.count("Negative")
|
95 |
total = len(sentiments)
|
@@ -109,7 +123,7 @@ if st.button("Get News and Sentiment"):
|
|
109 |
|
110 |
st.success(f"π **Overall Sentiment for `{ticker}`: {overall}**")
|
111 |
else:
|
112 |
-
st.info(f"No recent news
|
113 |
|
114 |
progress_bar.progress((idx + 1) / total_stocks)
|
115 |
time.sleep(0.1)
|
|
|
21 |
body {
|
22 |
background-color: #ffffff;
|
23 |
}
|
24 |
+
.title-wrapper {
|
25 |
+
display: inline-block;
|
26 |
+
white-space: nowrap;
|
27 |
+
overflow-x: auto;
|
28 |
+
max-width: 100%;
|
29 |
+
}
|
30 |
+
.title-wrapper::-webkit-scrollbar {
|
31 |
+
height: 4px;
|
32 |
+
}
|
33 |
+
.title-wrapper::-webkit-scrollbar-thumb {
|
34 |
+
background-color: #ccc;
|
35 |
+
border-radius: 2px;
|
36 |
+
}
|
37 |
+
.main-title {
|
38 |
color: #002b45;
|
39 |
font-family: 'Segoe UI', sans-serif;
|
40 |
+
font-size: 26px;
|
41 |
+
font-weight: 600;
|
42 |
+
margin: 0;
|
43 |
}
|
44 |
.stTextInput > div > div > input,
|
45 |
.stTextArea textarea {
|
|
|
61 |
</style>
|
62 |
""", unsafe_allow_html=True)
|
63 |
|
64 |
+
# ----------- Header Title (One-line, Scrollable if Long) -----------
|
65 |
st.markdown("""
|
66 |
+
<div class="title-wrapper">
|
67 |
+
<h1 class="main-title">π EquiPulse: Real-Time Stock News Sentiment</h1>
|
68 |
</div>
|
69 |
""", unsafe_allow_html=True)
|
70 |
|
71 |
+
# ----------- Description Section -----------
|
|
|
72 |
st.markdown("""
|
73 |
+
<div style='font-size:16px; line-height:1.6; color: #333333; margin-bottom: 1rem;'>
|
74 |
+
Analyze real-time financial sentiment from news headlines related to companies you're interested in.
|
75 |
</div>
|
76 |
""", unsafe_allow_html=True)
|
77 |
|
78 |
# ----------- Input Area -----------
|
79 |
+
st.markdown("#### π― Enter Company Tickers or Names")
|
80 |
+
free_text = st.text_area("Example: AAPL, NVIDIA, Tesla", height=90)
|
81 |
|
82 |
+
# ----------- Ticker Extraction -----------
|
83 |
ner_pipeline = get_ner_pipeline()
|
84 |
tickers = extract_org_entities(free_text, ner_pipeline)
|
85 |
|
86 |
if tickers:
|
87 |
+
st.markdown(f"β
**Recognized Tickers:** `{', '.join(tickers)}`")
|
88 |
else:
|
89 |
tickers = []
|
90 |
|
91 |
# ----------- Action Button -----------
|
92 |
+
if st.button("π Get News and Sentiment"):
|
93 |
if not tickers:
|
94 |
+
st.warning("β οΈ Please enter at least one recognizable company name or ticker.")
|
95 |
else:
|
96 |
sentiment_pipeline = get_sentiment_pipeline()
|
97 |
progress_bar = st.progress(0)
|
98 |
total_stocks = len(tickers)
|
99 |
|
100 |
for idx, ticker in enumerate(tickers):
|
101 |
+
st.markdown(f"---\n#### π Analyzing `{ticker}`")
|
102 |
|
103 |
news_list = fetch_news(ticker)
|
104 |
|
105 |
if news_list:
|
106 |
sentiments = [analyze_sentiment(news['title'], sentiment_pipeline) for news in news_list]
|
|
|
107 |
pos_count = sentiments.count("Positive")
|
108 |
neg_count = sentiments.count("Negative")
|
109 |
total = len(sentiments)
|
|
|
123 |
|
124 |
st.success(f"π **Overall Sentiment for `{ticker}`: {overall}**")
|
125 |
else:
|
126 |
+
st.info(f"No recent news found for `{ticker}`.")
|
127 |
|
128 |
progress_bar.progress((idx + 1) / total_stocks)
|
129 |
time.sleep(0.1)
|