Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -10,63 +10,60 @@ import time
|
|
10 |
|
11 |
# ----------- Page Config -----------
|
12 |
st.set_page_config(
|
13 |
-
page_title="Stock News Sentiment
|
14 |
layout="centered",
|
15 |
initial_sidebar_state="collapsed"
|
16 |
)
|
17 |
|
18 |
-
# ----------- Custom
|
19 |
st.markdown("""
|
20 |
<style>
|
21 |
body {
|
22 |
-
background-color: #
|
23 |
}
|
24 |
h1 {
|
25 |
-
color: #
|
26 |
font-family: 'Segoe UI', sans-serif;
|
|
|
27 |
}
|
28 |
.stTextInput > div > div > input,
|
29 |
.stTextArea textarea {
|
30 |
font-size: 16px;
|
31 |
}
|
32 |
.stButton>button {
|
33 |
-
background-color: #
|
34 |
color: white;
|
35 |
font-size: 16px;
|
36 |
padding: 0.4rem 1rem;
|
37 |
border-radius: 6px;
|
38 |
}
|
39 |
.stButton>button:hover {
|
40 |
-
background-color: #
|
|
|
|
|
|
|
41 |
}
|
42 |
</style>
|
43 |
""", unsafe_allow_html=True)
|
44 |
|
45 |
-
# ----------- Header Section
|
46 |
-
col1, col2 = st.columns([1,
|
47 |
with col1:
|
48 |
-
st.image(
|
49 |
-
"https://upload.wikimedia.org/wikipedia/commons/thumb/e/e8/Finance_Icon_Set_2013_-_Analytics.svg/1024px-Finance_Icon_Set_2013_-_Analytics.svg.png",
|
50 |
-
width=50
|
51 |
-
)
|
52 |
with col2:
|
53 |
-
st.markdown(
|
54 |
-
"<h1 style='margin-bottom: 0.3rem;'>Stock News Sentiment Analysis</h1>",
|
55 |
-
unsafe_allow_html=True
|
56 |
-
)
|
57 |
|
58 |
-
# ----------- Description
|
59 |
st.markdown("""
|
60 |
-
<div style='font-size:
|
61 |
-
|
62 |
-
<b>💬 Try:</b> <i>
|
63 |
-
<span style='color:gray; font-size:15px;'>Note: News retrieval depends on Finviz availability and structure.</span>
|
64 |
</div>
|
65 |
""", unsafe_allow_html=True)
|
66 |
|
67 |
# ----------- Input Area -----------
|
68 |
-
st.markdown("
|
69 |
-
free_text = st.text_area("
|
70 |
|
71 |
ner_pipeline = get_ner_pipeline()
|
72 |
tickers = extract_org_entities(free_text, ner_pipeline)
|
@@ -77,17 +74,16 @@ else:
|
|
77 |
tickers = []
|
78 |
|
79 |
# ----------- Action Button -----------
|
80 |
-
st.markdown("### 🚀 Run Analysis")
|
81 |
if st.button("Get News and Sentiment"):
|
82 |
if not tickers:
|
83 |
-
st.warning("⚠️ Please
|
84 |
else:
|
85 |
sentiment_pipeline = get_sentiment_pipeline()
|
86 |
progress_bar = st.progress(0)
|
87 |
total_stocks = len(tickers)
|
88 |
|
89 |
for idx, ticker in enumerate(tickers):
|
90 |
-
st.markdown(f"---\n
|
91 |
|
92 |
news_list = fetch_news(ticker)
|
93 |
|
@@ -100,9 +96,9 @@ if st.button("Get News and Sentiment"):
|
|
100 |
pos_ratio = pos_count / total if total else 0
|
101 |
neg_ratio = neg_count / total if total else 0
|
102 |
|
103 |
-
if pos_ratio >= 0.
|
104 |
overall = "Positive"
|
105 |
-
elif neg_ratio >= 0.
|
106 |
overall = "Negative"
|
107 |
else:
|
108 |
overall = "Neutral"
|
|
|
10 |
|
11 |
# ----------- Page Config -----------
|
12 |
st.set_page_config(
|
13 |
+
page_title="EquiPulse: Real-Time Stock News Sentiment",
|
14 |
layout="centered",
|
15 |
initial_sidebar_state="collapsed"
|
16 |
)
|
17 |
|
18 |
+
# ----------- Custom Styling -----------
|
19 |
st.markdown("""
|
20 |
<style>
|
21 |
body {
|
22 |
+
background-color: #ffffff;
|
23 |
}
|
24 |
h1 {
|
25 |
+
color: #002b45;
|
26 |
font-family: 'Segoe UI', sans-serif;
|
27 |
+
font-size: 32px;
|
28 |
}
|
29 |
.stTextInput > div > div > input,
|
30 |
.stTextArea textarea {
|
31 |
font-size: 16px;
|
32 |
}
|
33 |
.stButton>button {
|
34 |
+
background-color: #002b45;
|
35 |
color: white;
|
36 |
font-size: 16px;
|
37 |
padding: 0.4rem 1rem;
|
38 |
border-radius: 6px;
|
39 |
}
|
40 |
.stButton>button:hover {
|
41 |
+
background-color: #004b78;
|
42 |
+
}
|
43 |
+
.stMarkdown {
|
44 |
+
font-size: 16px;
|
45 |
}
|
46 |
</style>
|
47 |
""", unsafe_allow_html=True)
|
48 |
|
49 |
+
# ----------- Header Section -----------
|
50 |
+
col1, col2 = st.columns([1, 9])
|
51 |
with col1:
|
52 |
+
st.image("https://cdn-icons-png.flaticon.com/512/2721/2721203.png", width=48)
|
|
|
|
|
|
|
53 |
with col2:
|
54 |
+
st.markdown("<h1 style='margin-bottom: 0.2rem;'>EquiPulse: Real-Time Stock News Sentiment</h1>", unsafe_allow_html=True)
|
|
|
|
|
|
|
55 |
|
56 |
+
# ----------- Description -----------
|
57 |
st.markdown("""
|
58 |
+
<div style='font-size:16px; line-height:1.6;'>
|
59 |
+
Uncover real-time sentiment from financial headlines mentioning your target companies.<br>
|
60 |
+
<b>💬 Try:</b> <i>Apple, Tesla, and Microsoft</i>
|
|
|
61 |
</div>
|
62 |
""", unsafe_allow_html=True)
|
63 |
|
64 |
# ----------- Input Area -----------
|
65 |
+
st.markdown("#### 🎯 Enter Your Target Company Tickers")
|
66 |
+
free_text = st.text_area("Example: Apple, Nvidia, Google", height=90)
|
67 |
|
68 |
ner_pipeline = get_ner_pipeline()
|
69 |
tickers = extract_org_entities(free_text, ner_pipeline)
|
|
|
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: `{ticker}`")
|
87 |
|
88 |
news_list = fetch_news(ticker)
|
89 |
|
|
|
96 |
pos_ratio = pos_count / total if total else 0
|
97 |
neg_ratio = neg_count / total if total else 0
|
98 |
|
99 |
+
if pos_ratio >= 0.25:
|
100 |
overall = "Positive"
|
101 |
+
elif neg_ratio >= 0.75:
|
102 |
overall = "Negative"
|
103 |
else:
|
104 |
overall = "Neutral"
|