Update app.py
Browse files
app.py
CHANGED
@@ -15,9 +15,8 @@ def predict_sentiment(text):
|
|
15 |
input_ids = tf.constant(bert_tokenizer.encode(text, add_special_tokens=True))[None, :] # Menambahkan token khusus [CLS] dan [SEP]
|
16 |
logits = bert_model(input_ids)[0]
|
17 |
probabilities = tf.nn.softmax(logits, axis=1)
|
18 |
-
|
19 |
-
return
|
20 |
-
|
21 |
|
22 |
# Judul aplikasi
|
23 |
st.title('Prediksi Sentimen menggunakan BERT')
|
@@ -30,8 +29,8 @@ if st.button('Prediksi'):
|
|
30 |
if text.strip() == '':
|
31 |
st.warning('Masukkan teks terlebih dahulu.')
|
32 |
else:
|
33 |
-
|
34 |
-
if
|
35 |
-
st.error('Sentimen: Negatif')
|
36 |
else:
|
37 |
-
st.success('Sentimen: Positif')
|
|
|
15 |
input_ids = tf.constant(bert_tokenizer.encode(text, add_special_tokens=True))[None, :] # Menambahkan token khusus [CLS] dan [SEP]
|
16 |
logits = bert_model(input_ids)[0]
|
17 |
probabilities = tf.nn.softmax(logits, axis=1)
|
18 |
+
sentiment_score, sentiment_label = probabilities.numpy()[0]
|
19 |
+
return sentiment_score, sentiment_label
|
|
|
20 |
|
21 |
# Judul aplikasi
|
22 |
st.title('Prediksi Sentimen menggunakan BERT')
|
|
|
29 |
if text.strip() == '':
|
30 |
st.warning('Masukkan teks terlebih dahulu.')
|
31 |
else:
|
32 |
+
sentiment_score, sentiment_label = predict_sentiment(text)
|
33 |
+
if sentiment_label == 0:
|
34 |
+
st.error(f'Sentimen: Negatif, Skor: {sentiment_score:.2f}')
|
35 |
else:
|
36 |
+
st.success(f'Sentimen: Positif, Skor: {sentiment_score:.2f}')
|