Spaces:
Sleeping
Sleeping
Benjamin Consolvo
commited on
Commit
·
841f102
1
Parent(s):
cf6c896
formatting of text of headlines
Browse files
app.py
CHANGED
|
@@ -463,19 +463,17 @@ class TradingApp:
|
|
| 463 |
|
| 464 |
if symbol and sentiment_symbol == symbol and sentiment_result is not None:
|
| 465 |
st.markdown(f"**Sentiment for {symbol.upper()} ({sentiment_source}):** {sentiment_result if sentiment_result in ['Positive', 'Negative', 'Neutral'] else 'No sentiment available'}")
|
| 466 |
-
# Show the actual average score below
|
| 467 |
if sentiment_score is not None:
|
| 468 |
st.markdown(f"<span style='font-size:0.8em;color:#888;'>Average sentiment score: <b>{sentiment_score:.3f}</b></span>", unsafe_allow_html=True)
|
| 469 |
elif symbol and sentiment_symbol == symbol and sentiment_result is None:
|
| 470 |
st.markdown("**Sentiment:** No sentiment available")
|
| 471 |
|
| 472 |
-
# Shrink headlines font, number them, and use
|
| 473 |
if symbol and sentiment_symbol == symbol and article_headlines:
|
| 474 |
st.markdown(
|
| 475 |
"<div style='font-size: 0.75em; margin-bottom: 0.5em;'><b>Recent Headlines:</b></div>",
|
| 476 |
unsafe_allow_html=True
|
| 477 |
)
|
| 478 |
-
# Try to get URLs for headlines if available
|
| 479 |
headlines_with_links = []
|
| 480 |
try:
|
| 481 |
if sentiment_source == "NewsAPI":
|
|
@@ -496,25 +494,35 @@ class TradingApp:
|
|
| 496 |
headlines_with_links = [
|
| 497 |
(item.get("title"), item.get("url")) for item in feed if item.get("title")
|
| 498 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 499 |
else:
|
| 500 |
headlines_with_links = [(headline, None) for headline in article_headlines]
|
| 501 |
except Exception as e:
|
| 502 |
logger.error(f"Error fetching URLs for headlines: {e}")
|
| 503 |
headlines_with_links = [(headline, None) for headline in article_headlines]
|
| 504 |
|
| 505 |
-
# Use
|
| 506 |
for idx, (headline, url) in enumerate(headlines_with_links, 1):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 507 |
if url:
|
| 508 |
st.markdown(
|
| 509 |
-
f"<div style='font-size:0.75em; margin-bottom:0.15em; color
|
| 510 |
f"<span style='font-weight:bold;'>{idx}.</span> "
|
| 511 |
-
f"<a href='{url}' target='_blank' style='color
|
| 512 |
f"</div>",
|
| 513 |
unsafe_allow_html=True
|
| 514 |
)
|
| 515 |
else:
|
| 516 |
st.markdown(
|
| 517 |
-
f"<div style='font-size:0.75em; margin-bottom:0.15em; color
|
| 518 |
f"<span style='font-weight:bold;'>{idx}.</span> {headline}"
|
| 519 |
f"</div>",
|
| 520 |
unsafe_allow_html=True
|
|
|
|
| 463 |
|
| 464 |
if symbol and sentiment_symbol == symbol and sentiment_result is not None:
|
| 465 |
st.markdown(f"**Sentiment for {symbol.upper()} ({sentiment_source}):** {sentiment_result if sentiment_result in ['Positive', 'Negative', 'Neutral'] else 'No sentiment available'}")
|
|
|
|
| 466 |
if sentiment_score is not None:
|
| 467 |
st.markdown(f"<span style='font-size:0.8em;color:#888;'>Average sentiment score: <b>{sentiment_score:.3f}</b></span>", unsafe_allow_html=True)
|
| 468 |
elif symbol and sentiment_symbol == symbol and sentiment_result is None:
|
| 469 |
st.markdown("**Sentiment:** No sentiment available")
|
| 470 |
|
| 471 |
+
# Shrink headlines font, number them, and use white with underline for links if AlpacaNews, else blue
|
| 472 |
if symbol and sentiment_symbol == symbol and article_headlines:
|
| 473 |
st.markdown(
|
| 474 |
"<div style='font-size: 0.75em; margin-bottom: 0.5em;'><b>Recent Headlines:</b></div>",
|
| 475 |
unsafe_allow_html=True
|
| 476 |
)
|
|
|
|
| 477 |
headlines_with_links = []
|
| 478 |
try:
|
| 479 |
if sentiment_source == "NewsAPI":
|
|
|
|
| 494 |
headlines_with_links = [
|
| 495 |
(item.get("title"), item.get("url")) for item in feed if item.get("title")
|
| 496 |
]
|
| 497 |
+
elif sentiment_source == "AlpacaNews":
|
| 498 |
+
# Fetch Alpaca news with URLs
|
| 499 |
+
news_items = self.sentiment.alpaca_api.get_news(symbol, limit=5)
|
| 500 |
+
headlines_with_links = [
|
| 501 |
+
(item.headline, getattr(item, "url", None)) for item in news_items if hasattr(item, "headline")
|
| 502 |
+
]
|
| 503 |
else:
|
| 504 |
headlines_with_links = [(headline, None) for headline in article_headlines]
|
| 505 |
except Exception as e:
|
| 506 |
logger.error(f"Error fetching URLs for headlines: {e}")
|
| 507 |
headlines_with_links = [(headline, None) for headline in article_headlines]
|
| 508 |
|
| 509 |
+
# Use white for AlpacaNews, blue for others
|
| 510 |
for idx, (headline, url) in enumerate(headlines_with_links, 1):
|
| 511 |
+
if sentiment_source == "AlpacaNews":
|
| 512 |
+
color = "#fff"
|
| 513 |
+
else:
|
| 514 |
+
color = "#003366"
|
| 515 |
if url:
|
| 516 |
st.markdown(
|
| 517 |
+
f"<div style='font-size:0.75em; margin-bottom:0.15em; color:{color};'>"
|
| 518 |
f"<span style='font-weight:bold;'>{idx}.</span> "
|
| 519 |
+
f"<a href='{url}' target='_blank' style='color:{color}; text-decoration:underline;'>{headline}</a>"
|
| 520 |
f"</div>",
|
| 521 |
unsafe_allow_html=True
|
| 522 |
)
|
| 523 |
else:
|
| 524 |
st.markdown(
|
| 525 |
+
f"<div style='font-size:0.75em; margin-bottom:0.15em; color:{color};'>"
|
| 526 |
f"<span style='font-weight:bold;'>{idx}.</span> {headline}"
|
| 527 |
f"</div>",
|
| 528 |
unsafe_allow_html=True
|