Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -17,7 +17,7 @@ tokenizer = AutoTokenizer.from_pretrained(pretrained)
|
|
17 |
sentiment_analysis = pipeline("sentiment-analysis", model=model, tokenizer=tokenizer)
|
18 |
label_index = {'LABEL_0': 'positive', 'LABEL_1': 'neutral', 'LABEL_2': 'negative'}
|
19 |
|
20 |
-
st.title("Youtube Comment
|
21 |
st.write("Program ini akan menganalisis komentar dalam sebuah video di youtube menggunakan sentiment analysis, tidak termasuk komentar dalam komentar dan khusus untuk komentar bahasa indonesia")
|
22 |
|
23 |
# Input URL video
|
@@ -34,6 +34,8 @@ def analisis_sentimen(text):
|
|
34 |
return label, score
|
35 |
|
36 |
if st.button("Mulai Analisis"):
|
|
|
|
|
37 |
# Inisialisasi YoutubeCommentDownloader
|
38 |
downloader = YoutubeCommentDownloader()
|
39 |
|
@@ -63,22 +65,32 @@ if st.button("Mulai Analisis"):
|
|
63 |
st.info("Memulai analisis sentimen....")
|
64 |
|
65 |
# List untuk menyimpan hasil analisis sentimen
|
66 |
-
|
|
|
|
|
67 |
|
68 |
# Membaca data dari file CSV
|
69 |
with open('comments.csv', mode='r', encoding='utf-8') as file:
|
70 |
reader = csv.DictReader(file)
|
71 |
for row in tqdm(reader):
|
72 |
comment_text = row['text']
|
73 |
-
|
74 |
-
|
75 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
# Menampilkan hasil analisis sentimen
|
77 |
st.subheader("Hasil Analisis Sentimen")
|
78 |
-
#st.write(hasil_analisis)
|
79 |
|
80 |
# Menampilkan histogram
|
81 |
-
labels, scores = zip(*[(label, score) for _, label, score in hasil_analisis])
|
82 |
plt.hist(labels, bins=30, color='blue', alpha=0.7, edgecolor='black')
|
83 |
plt.xlabel('Skor Sentimen')
|
84 |
plt.ylabel('Jumlah Komentar')
|
|
|
17 |
sentiment_analysis = pipeline("sentiment-analysis", model=model, tokenizer=tokenizer)
|
18 |
label_index = {'LABEL_0': 'positive', 'LABEL_1': 'neutral', 'LABEL_2': 'negative'}
|
19 |
|
20 |
+
st.title("Indonesia Youtube Comment Sentiment Analysis")
|
21 |
st.write("Program ini akan menganalisis komentar dalam sebuah video di youtube menggunakan sentiment analysis, tidak termasuk komentar dalam komentar dan khusus untuk komentar bahasa indonesia")
|
22 |
|
23 |
# Input URL video
|
|
|
34 |
return label, score
|
35 |
|
36 |
if st.button("Mulai Analisis"):
|
37 |
+
#Memulai Download Komentar
|
38 |
+
st.info("Memulai Download Komentar....")
|
39 |
# Inisialisasi YoutubeCommentDownloader
|
40 |
downloader = YoutubeCommentDownloader()
|
41 |
|
|
|
65 |
st.info("Memulai analisis sentimen....")
|
66 |
|
67 |
# List untuk menyimpan hasil analisis sentimen
|
68 |
+
scores = []
|
69 |
+
labels = []
|
70 |
+
# hasil_analisis = []
|
71 |
|
72 |
# Membaca data dari file CSV
|
73 |
with open('comments.csv', mode='r', encoding='utf-8') as file:
|
74 |
reader = csv.DictReader(file)
|
75 |
for row in tqdm(reader):
|
76 |
comment_text = row['text']
|
77 |
+
# Bagi teks menjadi bagian-bagian dengan panjang maksimum 512 token
|
78 |
+
parts = [comment_text[i:i+512] for i in range(0, len(comment_text), 512)]
|
79 |
+
for part in parts:
|
80 |
+
# Analisis sentimen
|
81 |
+
result = sentiment_analysis(part)
|
82 |
+
label = label_index[result[0]['label']]
|
83 |
+
score = result[0]['score'] * 100
|
84 |
+
labels.append(label)
|
85 |
+
scores.append(score)
|
86 |
+
# hasil_analisis.append((comment_text, label, score))
|
87 |
+
|
88 |
# Menampilkan hasil analisis sentimen
|
89 |
st.subheader("Hasil Analisis Sentimen")
|
90 |
+
# st.write(hasil_analisis)
|
91 |
|
92 |
# Menampilkan histogram
|
93 |
+
# labels, scores = zip(*[(label, score) for _, label, score in hasil_analisis])
|
94 |
plt.hist(labels, bins=30, color='blue', alpha=0.7, edgecolor='black')
|
95 |
plt.xlabel('Skor Sentimen')
|
96 |
plt.ylabel('Jumlah Komentar')
|