Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -79,35 +79,40 @@ def analyze_sentiment(comment):
|
|
79 |
|
80 |
def main():
|
81 |
st.title("YouTube Comments Sentiment Analysis")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
82 |
st.write("Enter a YouTube video link below:")
|
83 |
-
|
84 |
video_url = st.text_input("YouTube Video URL:")
|
|
|
85 |
if st.button("Extract Comments and Analyze"):
|
86 |
video_id = extract_video_id(video_url)
|
87 |
if video_id:
|
88 |
comments_df = fetch_comments(video_id)
|
89 |
-
# Comments is a dataframe of just the comments text
|
90 |
-
# st.write("Top 100 Comments extracted\n", comments_df)
|
91 |
comments_df['sentiment'] = comments_df['comment'].apply(lambda x: analyze_sentiment(x[:512]))
|
92 |
sentiment_counts = comments_df['sentiment'].value_counts()
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
# Create pie chart in col2 with custom colors
|
98 |
-
fig_pie = px.pie(values=[positive_count, negative_count, neutral_count],
|
99 |
-
names=['Positive', 'Negative', 'Neutral'],
|
100 |
-
title='Pie chart representations',
|
101 |
-
color=sentiment_counts.index, # Use sentiment categories as colors
|
102 |
-
color_discrete_map={'Positive': 'green', 'Negative': 'red', 'Neutral': 'blue'})
|
103 |
st.plotly_chart(fig_pie, use_container_width=True)
|
104 |
|
105 |
-
# Create bar chart
|
106 |
-
fig_bar = px.bar(x=sentiment_counts.index, y=sentiment_counts.values,
|
107 |
-
labels={'x': 'Sentiment', 'y': 'Count'},
|
108 |
-
title='Bar plot representations',
|
109 |
-
color=sentiment_counts.index, # Use sentiment categories as colors
|
110 |
-
color_discrete_map={'Positive': 'green', 'Negative': 'red', 'Neutral': 'blue'})
|
111 |
st.plotly_chart(fig_bar)
|
112 |
|
113 |
|
|
|
79 |
|
80 |
def main():
|
81 |
st.title("YouTube Comments Sentiment Analysis")
|
82 |
+
|
83 |
+
# Create sidebar section for app description and links
|
84 |
+
st.sidebar.title("App Information")
|
85 |
+
st.sidebar.write("Welcome to the YouTube Comments Sentiment Analysis App.")
|
86 |
+
st.sidebar.write("This app extracts comments from a YouTube video and analyzes their sentiment.")
|
87 |
+
st.sidebar.write("Feel free to check out our other apps:")
|
88 |
+
|
89 |
+
# Dropdown menu for other app links
|
90 |
+
app_links = {
|
91 |
+
"App 1": "https://your-app-1-url.com",
|
92 |
+
"App 2": "https://your-app-2-url.com"
|
93 |
+
}
|
94 |
+
selected_app = st.sidebar.selectbox("Select an App", list(app_links.keys()))
|
95 |
+
if st.sidebar.button("Go to App"):
|
96 |
+
st.sidebar.write(f"You are now redirected to {selected_app}")
|
97 |
+
st.sidebar.write(f"Link: {app_links[selected_app]}")
|
98 |
+
st.sidebar.success("Redirected successfully!")
|
99 |
+
|
100 |
st.write("Enter a YouTube video link below:")
|
|
|
101 |
video_url = st.text_input("YouTube Video URL:")
|
102 |
+
|
103 |
if st.button("Extract Comments and Analyze"):
|
104 |
video_id = extract_video_id(video_url)
|
105 |
if video_id:
|
106 |
comments_df = fetch_comments(video_id)
|
|
|
|
|
107 |
comments_df['sentiment'] = comments_df['comment'].apply(lambda x: analyze_sentiment(x[:512]))
|
108 |
sentiment_counts = comments_df['sentiment'].value_counts()
|
109 |
+
|
110 |
+
# Create pie chart
|
111 |
+
fig_pie = px.pie(values=sentiment_counts.values, names=sentiment_counts.index, title='Sentiment Distribution')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
112 |
st.plotly_chart(fig_pie, use_container_width=True)
|
113 |
|
114 |
+
# Create bar chart
|
115 |
+
fig_bar = px.bar(x=sentiment_counts.index, y=sentiment_counts.values, labels={'x': 'Sentiment', 'y': 'Count'}, title='Sentiment Counts')
|
|
|
|
|
|
|
|
|
116 |
st.plotly_chart(fig_bar)
|
117 |
|
118 |
|