Spaces:
Running
Running
Benjamin Consolvo
commited on
Commit
·
b44b4b2
1
Parent(s):
0f500af
check manual sentiment
Browse files
app.py
CHANGED
@@ -416,6 +416,40 @@ class TradingApp:
|
|
416 |
else:
|
417 |
st.error("Please enter a valid stock symbol and trade details.")
|
418 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
419 |
# Display portfolio information in the sidebar
|
420 |
st.header("Alpaca Cash Portfolio")
|
421 |
|
|
|
416 |
else:
|
417 |
st.error("Please enter a valid stock symbol and trade details.")
|
418 |
|
419 |
+
# --- Sentiment Check Feature ---
|
420 |
+
sentiment_result = None
|
421 |
+
article_headlines = []
|
422 |
+
if st.button("Check Sentiment"):
|
423 |
+
if symbol:
|
424 |
+
try:
|
425 |
+
# Use NewsSentiment to get sentiment and articles
|
426 |
+
sentiment_dict = self.sentiment.get_news_sentiment([symbol])
|
427 |
+
sentiment_result = sentiment_dict.get(symbol)
|
428 |
+
# Try to fetch article headlines
|
429 |
+
try:
|
430 |
+
articles = self.sentiment.newsapi.get_everything(q=symbol, language='en', sort_by='publishedAt', page=1)
|
431 |
+
article_headlines = [a['title'] for a in articles.get('articles', [])[:5]]
|
432 |
+
except Exception as e:
|
433 |
+
article_headlines = []
|
434 |
+
except Exception as e:
|
435 |
+
sentiment_result = None
|
436 |
+
article_headlines = []
|
437 |
+
else:
|
438 |
+
sentiment_result = None
|
439 |
+
article_headlines = []
|
440 |
+
|
441 |
+
if sentiment_result is not None:
|
442 |
+
st.markdown(f"**Sentiment for {symbol.upper()}:** {sentiment_result if sentiment_result in ['Positive', 'Negative', 'Neutral'] else 'No sentiment available'}")
|
443 |
+
elif sentiment_result is None and st.session_state.get("Check Sentiment"):
|
444 |
+
st.markdown("**Sentiment:** No sentiment available")
|
445 |
+
|
446 |
+
if article_headlines:
|
447 |
+
st.markdown("**Recent Headlines:**")
|
448 |
+
for headline in article_headlines:
|
449 |
+
st.write(f"- {headline}")
|
450 |
+
elif sentiment_result is not None and not article_headlines:
|
451 |
+
st.markdown("_No headlines available._")
|
452 |
+
|
453 |
# Display portfolio information in the sidebar
|
454 |
st.header("Alpaca Cash Portfolio")
|
455 |
|