File size: 4,892 Bytes
890ed4f ca12572 890ed4f ca12572 890ed4f ca12572 890ed4f ca12572 890ed4f ca12572 890ed4f ca12572 890ed4f ca12572 890ed4f ca12572 eae5fab ca12572 eae5fab ca12572 eae5fab ca12572 eae5fab 30bf2ff 8918686 30bf2ff 890ed4f 4307f05 890ed4f 30bf2ff 16adfc0 bafb2ab 16adfc0 890ed4f 6fafb78 16adfc0 890ed4f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
import streamlit as st
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
import pandas as pd
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
import sys
from datetime import datetime
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.service import Service as ChromeService
from webdriver_manager.core.os_manager import ChromeType
import re
import transformers
from transformers import DistilBertTokenizer, DistilBertForSequenceClassification
import io
import plotly.express as px
import zipfile
import torch
with st.sidebar:
st.button("DEMO APP", type="primary")
expander = st.expander("**Important notes on the YouTube Comments Sentiment Analysis App**")
expander.write('''
**How to Use**
This app works with a YouTube URL. Paste the URL and press the 'Sentiment Analysis' button to perform sentiment analysis on your YouTube Comments.
**Usage Limits**
You can perform sentiment analysis on YouTube Comments up to 5 times.
**Subscription Management**
This demo app offers a one-day subscription, expiring after 24 hours. If you are interested in building your own YouTube Comments Sentiment Analysis Web App, we invite you to explore our NLP Web App Store on our website. You can select your desired features, place your order, and we will deliver your custom app in five business days. If you wish to delete your Account with us, please contact us at info@nlpblogs.com
**Customization**
To change the app's background color to white or black, click the three-dot menu on the right-hand side of your app, go to Settings and then Choose app theme, colors and fonts.
**Charts**
Hover to interact with and download the charts.
**File Handling and Errors**
For any errors or inquiries, please contact us at info@nlpblogs.com
''')
def clear_question():
st.session_state["url"] = ""
url = st.text_input("Enter YouTube URL:", key="url")
st.button("Clear question", on_click=clear_question)
if st.button("Sentiment Analysis", type="secondary"):
if st.session_state['url_count'] < max_attempts:
if url:
with st.spinner("Wait for it...", show_time=True):
options = Options()
options.add_argument("--headless")
options.add_argument("--disable-gpu")
options.add_argument("--no-sandbox")
options.add_argument("--disable-dev-shm-usage")
options.add_argument("--start-maximized")
service = Service(ChromeDriverManager(chrome_type=ChromeType.CHROMIUM).install())
driver = webdriver.Chrome(service=service, options=options)
data = []
wait = WebDriverWait(driver, 30)
driver.get(url)
placeholder = st.empty()
progress_bar = st.progress(0)
for item in range(30):
try:
body = WebDriverWait(driver, 30).until(EC.visibility_of_element_located((By.TAG_NAME, "body")))
body.send_keys(Keys.END)
placeholder.text(f"Scrolled {item + 1} times")
progress_bar.progress((item + 1) / 150)
time.sleep(0.5)
except Exception as e:
st.error(f"Exception during scrolling: {e}")
break
placeholder.text("Scrolling complete.")
progress_bar.empty()
videos = driver.find_elements_by_class_name('style-scope ytd-grid-video-renderer')
youtube_videos = []
for video in videos:
link = url
title = video.find_element_by_xpath(By.XPATH, './/*[@id="video-title"]').text
views = video.find_element_by_xpath(By.XPATH,'.//*[@id="metadata-line"]/span[1]').text
date = video.find_element_by_xpath(By.XPATH,'.//*[@id="metadata-line"]/span[2]').text
vid_items = {
'Title': title,
'Views': views,
'Posted': date,
'Likes' : likes,
'link': link
}
youtube_videos.append(vid_items)
df = pd.DataFrame(youtube_videos)
st.dataframe(df)
|