Getting Blank Output on streamlit dashboard ran from local windows11 machine


I’m trying to build a Stock Market News Sentiment analysis app using streamlit. But I’m getting blank outputs for every company I select from the select box. I’m not able to figure out what is wrong in my code: Please help me to resolve the issue:
(Using Python 3.11 and streamlit 1.31.1)

import Libraries

import streamlit as st
import pandas as pd
import requests
import numpy as np
import yfinance as yf
import as px
import plotly.graph_objects as go
from PIL import Image
from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer


get nifty500 data

def get_nifty500_components():
df = pd.read_html(“NIFTY 500 - Wikipedia”,match=‘Nifty 500 List’)
df = df[0]
df.columns = df.iloc[0]
df[“Symbol”] = df[“Symbol”] + ‘.NS’
tickers = df[“Symbol”].to_list()
tickers_companies_dict = dict(
zip(df[“Symbol”], df[“Company Name”])
return tickers, tickers_companies_dict

available_tickers, tickers_companies_dict = get_nifty500_components()

ticker = st.selectbox(
“Select Company”,

Initialize VADER so we can use it later

sentimentAnalyser = SentimentIntensityAnalyzer()

#Calculate the Sentiment Score Of Each News
def calculate_sentiment(text):
# Run VADER on text
score = sentimentAnalyser.polarity_scores(text)
#Extract compound score
compound_score = score[‘compound’]
return compound_score

Create Sentiment Category:

def sentiment_category(text):
# Run VADER on text
score = sentimentAnalyser.polarity_scores(text)
#Extract compound score
compound_score = score[‘compound’]
if compound_score > 0.05:
return ‘positive’
elif compound_score <= -0.05:
return ‘negative’
return ‘neutral’

get the news from newsapi


news_params = {
“apiKey”: NEWS_API_KEY,
“qInTitle”: ticker,
news_response = requests.get(NEWS_ENDPOINT, params=news_params)
articles = news_response.json()[“articles”]
sixteen_articles = articles[:16]
formatted_articles = [(f"{ticker}“,f”{article[‘title’]}“,f”{article[‘description’]}“,f”{article[‘url’]}“,f”{article[‘publishedAt’]}") for article in sixteen_articles]

df_news = pd.DataFrame(formatted_articles,columns=[‘Company’,‘Headline’,‘Brief’,‘URL’,‘Timestamp’])
df_news[‘Timestamp’] = pd.to_datetime(df_news[‘Timestamp’])
df_news[‘Sentiment Score’] = df_news[‘Brief’].apply(calculate_sentiment)
df_news[‘sentiment Category’] = df_news[‘Brief’].apply(sentiment_category)
df_news = df_news.sort_values(by=[‘Timestamp’],ascending=True).reset_index(drop=True)

st.header(f’News of {tickers_companies_dict[ticker]}')


for i in range(16):
st.subheader(f’News {i + 1}‘)
sentiment_score = str(df_news[‘Sentiment Score’][i])
st.write(f’Sentiment Score {sentiment_score}’)
news_sentiment = str(df_news[‘sentiment Category’][i])
st.write(f’News Sentiment{news_sentiment}')

Plot the sentiments over time as a line graph

fig = px.line(df_news, x=“Timestamp”, y=“Sentiment Score”,color=‘sentiment Category’,
text=df_news[“Sentiment Score”].round(1).to_list(),
markers=True, color_discrete_sequence=[“green”,“red”,“goldenrod”])
fig.update_traces(textposition=“bottom right”)

I think the @st.cache decorator has been removed from get_nifty500_components to ensure the ticker information is always up-to-date. so try to change it so that it can give information up to date.