mabzak commited on
Commit
179f432
1 Parent(s): 6c7af8c

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +54 -0
  2. requirements.txt +5 -0
app.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from tqdm import tqdm
2
+ from itertools import islice
3
+ from youtube_comment_downloader import *
4
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
5
+
6
+ import matplotlib.pyplot as plt
7
+ import csv
8
+ import streamlit as st
9
+ import pandas as pd
10
+ import base64
11
+
12
+ st.title("Youtube Comment Downloader")
13
+
14
+ # Input URL video
15
+ video_url = st.text_input("Masukkan URL video YouTube:")
16
+
17
+ # Input jumlah komentar yang ingin diambil
18
+ num_comments = st.number_input("Jumlah komentar yang ingin diambil:", min_value=1, value=10)
19
+
20
+ if st.button("Ambil Data Komentar"):
21
+ # Inisialisasi YoutubeCommentDownloader
22
+ downloader = YoutubeCommentDownloader()
23
+
24
+ # Mendapatkan komentar
25
+ comments = downloader.get_comments_from_url(video_url, sort_by=SORT_BY_POPULAR)
26
+
27
+ # Membuka file CSV untuk menulis
28
+ with open('comments.csv', mode='w', encoding='utf-8', newline='') as file:
29
+ # Membuat objek writer
30
+ writer = csv.DictWriter(file, fieldnames=['cid', 'text', 'time', 'author', 'channel', 'votes', 'photo', 'heart', 'reply'])
31
+
32
+ # Menulis header
33
+ writer.writeheader()
34
+
35
+ # Menulis data komentar
36
+ for comment in tqdm(islice(comments, num_comments)):
37
+ # Menghapus kolom 'time_parsed' dari komentar
38
+ comment.pop('time_parsed', None)
39
+ writer.writerow(comment)
40
+
41
+ st.success(f"Komentar berhasil diunduh dan disimpan dalam file 'comments.csv'")
42
+
43
+ # Membaca data dari file CSV
44
+ comments_df = pd.read_csv('comments.csv')
45
+
46
+ # Menampilkan tabel dengan menggunakan st.table()
47
+ st.subheader("Data Komentar")
48
+ st.table(comments_df)
49
+
50
+ # Menyiapkan link untuk mendownload file CSV
51
+ csv = comments_df.to_csv(index=False)
52
+ b64 = base64.b64encode(csv.encode()).decode()
53
+ href = f'<a style="background-color: #008CBA; color: white; padding: 10px 20px; text-decoration: none; border-radius: 5px; font-weight: bold;" href="data:file/csv;base64,{b64}" download="comments.csv">Download File CSV</a>'
54
+ st.markdown(href, unsafe_allow_html=True)
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ youtube-comment-downloader
2
+ tqdm
3
+ torch
4
+ transformers
5
+ matplotlib