from helper import extract_youtube_id, get_all_comments import streamlit as st import random import pandas as pd import numpy as np st.header("💬 Youtube Comments Sentiment Analysis") st.markdown(""" """, unsafe_allow_html=True) user_input = st.text_input("Enter a youtube link for sentiment analysis") sentiment_colors = { "Positive": "#28a745", "Neutral": "#ffc107", "Negative": "#dc3545" } if st.button('Submit', type="secondary"): sentiments = ["Positive", "Neutral", "Negative"] try: the_youtube_id = extract_youtube_id(user_input) if the_youtube_id: with st.spinner("Please wait while we're loading the data..."): the_data = get_all_comments(the_youtube_id) data = np.random.choice(["Positive", "Neutral", "Negative"], size=len(the_data)) # Create a DataFrame sentiment_data = pd.DataFrame(data, columns=["Sentiment"]) sentiment_counts = sentiment_data["Sentiment"].value_counts() positives = sentiment_counts.get("Positive", 0) neutrals = sentiment_counts.get("Neutral", 0) negatives = sentiment_counts.get("Negative", 0) st.balloons() st.markdown(f"""

Total comments: {len(the_data)}

""", unsafe_allow_html=True) st.markdown(f"""

Positives: {positives}

""", unsafe_allow_html=True) st.markdown(f"""

Neutrals: {neutrals}

""", unsafe_allow_html=True) st.markdown(f"""

Negatives: {negatives}

""", unsafe_allow_html=True) for index, data in enumerate(the_data): sentiment_color = sentiment_colors.get(sentiment_data.iloc[index, 0], "#6c757d") comment_html = f"""

{data["comment"]}

Sentiment Analysis: {sentiment_data.iloc[index, 0]}

""" st.markdown(comment_html, unsafe_allow_html=True) else: st.write("Invalid youtube link.") except Exception as e: print(e) st.write("Invalid youtube link.")