Update app.py
Browse files
app.py
CHANGED
|
@@ -25,21 +25,21 @@ def predict_sentiment(text):
|
|
| 25 |
return_tensors='tf'
|
| 26 |
)
|
| 27 |
|
| 28 |
-
#
|
| 29 |
-
|
| 30 |
-
input_ids
|
| 31 |
-
attention_mask
|
| 32 |
-
|
|
|
|
|
|
|
| 33 |
|
| 34 |
-
# Ambil
|
| 35 |
prediction = tf.argmax(outputs["classifier"], axis=1).numpy()[0]
|
| 36 |
return labels[prediction]
|
| 37 |
|
| 38 |
# UI Gradio
|
| 39 |
-
demo = gr.Interface(
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
outputs=gr.Textbox(label="Hasil Sentimen")
|
| 43 |
-
)
|
| 44 |
|
| 45 |
demo.launch()
|
|
|
|
| 25 |
return_tensors='tf'
|
| 26 |
)
|
| 27 |
|
| 28 |
+
# Gabungkan input_ids dan attention_mask ke dalam 1 dict
|
| 29 |
+
model_inputs = {
|
| 30 |
+
"input_ids": inputs["input_ids"],
|
| 31 |
+
"attention_mask": inputs["attention_mask"]
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
outputs = model(inputs=model_inputs)
|
| 35 |
|
| 36 |
+
# Ambil prediksi dari output dict
|
| 37 |
prediction = tf.argmax(outputs["classifier"], axis=1).numpy()[0]
|
| 38 |
return labels[prediction]
|
| 39 |
|
| 40 |
# UI Gradio
|
| 41 |
+
demo = gr.Interface(fn=predict_sentiment,
|
| 42 |
+
inputs=gr.Textbox(label="Masukkan komentar"),
|
| 43 |
+
outputs=gr.Textbox(label="Hasil Sentimen"))
|
|
|
|
|
|
|
| 44 |
|
| 45 |
demo.launch()
|