Update app.py
Browse files
app.py
CHANGED
@@ -65,10 +65,15 @@ if st.button("Sentiment Analysis", type="secondary"):
|
|
65 |
progress_bar.empty()
|
66 |
try:
|
67 |
wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, "#contents #contents")))
|
68 |
-
comments = driver.find_elements(By.CSS_SELECTOR, "#content #content-text")
|
69 |
user_id = 1
|
70 |
for comment in comments:
|
71 |
-
timestamp =
|
|
|
|
|
|
|
|
|
|
|
72 |
data.append({"User ID": user_id, "Comment": comment.text, "comment_date": timestamp})
|
73 |
user_id += 1
|
74 |
data = [dict(t) for t in {tuple(d.items()) for d in data}]
|
@@ -78,7 +83,7 @@ if st.button("Sentiment Analysis", type="secondary"):
|
|
78 |
df = pd.DataFrame(data, columns=["User ID", "Comment", "comment_date"])
|
79 |
st.dataframe(df)
|
80 |
|
81 |
-
if not df.empty and 'Comment' in df.columns and not df['Comment'].empty:
|
82 |
inputs = tokenizer(df['Comment'].tolist(), return_tensors="pt", padding=True, truncation=True)
|
83 |
with torch.no_grad():
|
84 |
logits = model(**inputs).logits
|
|
|
65 |
progress_bar.empty()
|
66 |
try:
|
67 |
wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, "#contents #contents")))
|
68 |
+
comments = driver.find_elements(By.CSS_SELECTOR, "#content #content-text")
|
69 |
user_id = 1
|
70 |
for comment in comments:
|
71 |
+
timestamp = None
|
72 |
+
try:
|
73 |
+
timestamp_element = comment.find_element(By.XPATH, './ancestor::ytd-comment-renderer//yt-formatted-string[@class="published-time-text style-scope ytd-comment-renderer"]')
|
74 |
+
timestamp = timestamp_element.text
|
75 |
+
except Exception as e:
|
76 |
+
print(f"Date not found for comment: {comment.text}. Error: {e}")
|
77 |
data.append({"User ID": user_id, "Comment": comment.text, "comment_date": timestamp})
|
78 |
user_id += 1
|
79 |
data = [dict(t) for t in {tuple(d.items()) for d in data}]
|
|
|
83 |
df = pd.DataFrame(data, columns=["User ID", "Comment", "comment_date"])
|
84 |
st.dataframe(df)
|
85 |
|
86 |
+
if not df.empty and 'Comment' in df.columns and not df['Comment'].empty:
|
87 |
inputs = tokenizer(df['Comment'].tolist(), return_tensors="pt", padding=True, truncation=True)
|
88 |
with torch.no_grad():
|
89 |
logits = model(**inputs).logits
|