GoodML commited on
Commit
ee5fb0e
1 Parent(s): 8df268e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -1
app.py CHANGED
@@ -55,7 +55,22 @@ def extract_video_id(video_url):
55
  def fetch_comments(video_id):
56
  # Example using youtube-comment-scraper-python library
57
  comments = scrape_comments(video_id)
58
- return comments
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
 
60
  # Function to analyze sentiment for a single comment
61
  def analyze_sentiment(comment):
@@ -138,6 +153,9 @@ def main():
138
  comments_df['sentiment'] = comments_df['comment'].apply(lambda x: analyze_sentiment(x[:512]))
139
  sentiment_counts = comments_df['sentiment'].value_counts()
140
 
 
 
 
141
  st.write("Based on top :100: comments from this video")
142
  # Create pie chart
143
  st.write("Pie chart representation :chart_with_upwards_trend:")
 
55
  def fetch_comments(video_id):
56
  # Example using youtube-comment-scraper-python library
57
  comments = scrape_comments(video_id)
58
+
59
+ request = youtube.videos().list(
60
+ part="snippet",
61
+ id=video_id
62
+ )
63
+ response = request.execute()
64
+
65
+ if response['items']:
66
+ video_info = response['items'][0]['snippet']
67
+ channel_name = video_info['channelTitle']
68
+ video_description = video_info['description']
69
+ else:
70
+ channel_name = "Unknown"
71
+ video_description = "No description available"
72
+
73
+ return comments, channel_name, video_description
74
 
75
  # Function to analyze sentiment for a single comment
76
  def analyze_sentiment(comment):
 
153
  comments_df['sentiment'] = comments_df['comment'].apply(lambda x: analyze_sentiment(x[:512]))
154
  sentiment_counts = comments_df['sentiment'].value_counts()
155
 
156
+ st.write(f"**Channel Name:** {channel_name}")
157
+ st.write(f"**Video Description:** {video_description}")
158
+
159
  st.write("Based on top :100: comments from this video")
160
  # Create pie chart
161
  st.write("Pie chart representation :chart_with_upwards_trend:")