LinkLinkWu commited on
Commit
ade49f8
·
verified ·
1 Parent(s): 28c2a98

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -35
app.py CHANGED
@@ -1,57 +1,56 @@
1
  import streamlit as st
2
  from func import fetch_news, analyze_sentiment, extract_org_entities
3
-
4
  import time
5
 
6
  # ---------------- Page Setup ----------------
7
  st.set_page_config(page_title="Stock News Sentiment Analysis", layout="centered")
8
 
9
- st.markdown("""
10
- <style>
11
- .main { background-color: #f9fbfc; }
12
- .stTextInput>div>div>input, .stTextArea textarea {
13
- font-size: 16px;
14
- padding: 0.5rem;
15
- }
16
- .stButton>button {
17
- background-color: #4CAF50;
18
- color: white;
19
- font-size: 16px;
20
- padding: 0.5rem 1rem;
21
- border-radius: 8px;
22
- }
23
- .stButton>button:hover {
24
- background-color: #45a049;
25
- }
26
- </style>
27
- """, unsafe_allow_html=True)
28
 
29
- # ---------------- User Interface ----------------
30
- st.title("\U0001F4CA Stock News Sentiment Analysis")
31
- st.markdown("""
32
- This tool analyzes the sentiment of news articles related to companies you mention in text.
33
- \U0001F4A1 *Try input tickers like:* `AAPL, NKE, META`
34
- **Note:** If news fetching fails, it may be due to changes in the Finviz website or access restrictions.
35
- """)
 
 
 
 
 
 
 
36
 
 
37
  free_text = st.text_area("Enter text mentioning companies:", height=100)
38
  tickers = extract_org_entities(free_text)
39
 
40
  if tickers:
41
- cleaned_input = ", ".join(tickers)
42
- st.markdown(f"\U0001F50E **Identified Tickers:** `{cleaned_input}`")
43
  else:
44
  tickers = []
45
 
46
- # ---------------- Button Trigger ----------------
47
  if st.button("Get News and Sentiment"):
48
  if not tickers:
49
  st.warning("Please mention at least one recognizable company.")
50
  else:
51
  progress_bar = st.progress(0)
52
  total_stocks = len(tickers)
 
53
  for idx, ticker in enumerate(tickers):
54
- st.subheader(f"Analyzing {ticker}...")
55
  news_list = fetch_news(ticker)
56
 
57
  if news_list:
@@ -73,12 +72,12 @@ if st.button("Get News and Sentiment"):
73
  else:
74
  overall_sentiment = "Neutral"
75
 
76
- st.write(f"**Top 3 News Articles for {ticker}**")
77
  for i, news in enumerate(news_list[:3], 1):
78
- sentiment = sentiments[i-1]
79
- st.markdown(f"{i}. [{news['title']}]({news['link']}) - **{sentiment}**")
80
 
81
- st.write(f"**Overall Sentiment for {ticker}: {overall_sentiment}**")
82
  else:
83
  st.write(f"No news available for {ticker}.")
84
 
 
1
  import streamlit as st
2
  from func import fetch_news, analyze_sentiment, extract_org_entities
 
3
  import time
4
 
5
  # ---------------- Page Setup ----------------
6
  st.set_page_config(page_title="Stock News Sentiment Analysis", layout="centered")
7
 
8
+ # ---------------- Page Header ----------------
9
+ st.markdown(
10
+ """
11
+ <h1 style="display: flex; align-items: center;">
12
+ <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/e/e8/Finance_Icon_Set_2013_-_Analytics.svg/1024px-Finance_Icon_Set_2013_-_Analytics.svg.png"
13
+ alt="icon" width="40" style="margin-right: 10px;">
14
+ Stock News Sentiment Analysis
15
+ </h1>
16
+ """,
17
+ unsafe_allow_html=True
18
+ )
 
 
 
 
 
 
 
 
19
 
20
+ st.markdown(
21
+ """
22
+ <p style="font-size:17px; margin-top: 0.5rem;">
23
+ Analyze the latest news sentiment of companies mentioned in your input.
24
+ </p>
25
+ <p style="font-size:17px;">
26
+ <strong>💡 Try input like:</strong> <em>I want to check Apple, Tesla, and Microsoft.</em>
27
+ </p>
28
+ <p style="font-size:17px;">
29
+ <strong>Note:</strong> News may fail to load if the Finviz website structure changes or access is restricted.
30
+ </p>
31
+ """,
32
+ unsafe_allow_html=True
33
+ )
34
 
35
+ # ---------------- Input Area ----------------
36
  free_text = st.text_area("Enter text mentioning companies:", height=100)
37
  tickers = extract_org_entities(free_text)
38
 
39
  if tickers:
40
+ st.markdown(f"\U0001F50E **Identified Tickers:** `{', '.join(tickers)}`")
 
41
  else:
42
  tickers = []
43
 
44
+ # ---------------- Analysis Trigger ----------------
45
  if st.button("Get News and Sentiment"):
46
  if not tickers:
47
  st.warning("Please mention at least one recognizable company.")
48
  else:
49
  progress_bar = st.progress(0)
50
  total_stocks = len(tickers)
51
+
52
  for idx, ticker in enumerate(tickers):
53
+ st.subheader(f"🔍 Analyzing {ticker}")
54
  news_list = fetch_news(ticker)
55
 
56
  if news_list:
 
72
  else:
73
  overall_sentiment = "Neutral"
74
 
75
+ st.write(f"**Top 3 News Articles for {ticker}:**")
76
  for i, news in enumerate(news_list[:3], 1):
77
+ sentiment = sentiments[i - 1]
78
+ st.markdown(f"{i}. [{news['title']}]({news['link']}) **{sentiment}**")
79
 
80
+ st.success(f"**Overall Sentiment for {ticker}: {overall_sentiment}**")
81
  else:
82
  st.write(f"No news available for {ticker}.")
83