-
Notifications
You must be signed in to change notification settings - Fork 0
/
streamlit_app.py
55 lines (45 loc) · 1.52 KB
/
streamlit_app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import streamlit as st
from transformers import pipeline
import torch
# Select GPU if available, otherwise CPU
device = 0 if torch.cuda.is_available() else -1
# Load the model using pipeline
pipe = pipeline("sentiment-analysis",
model="azizp128/javanese-sentiment-analysis-indobert")
# Initialize session state for result
if "result" not in st.session_state:
st.session_state.result = None
st.markdown(
"""
<h1 style="text-align: center; font-family: sans-serif;">
Analisis Sentimen Bahasa Jawa Ngoko Lugu
</h1>
<hr>
""",
unsafe_allow_html=True
)
# Description
st.write("Model analisis sentimen berbasis IndoBERT yang dapat memprediksi sentimen positif atau negatif dari teks berbahasa Jawa Ngoko Lugu.")
# User input
user_input = st.text_input("Input", placeholder="Masukkan teks")
# Examples
options = ["Aku tresno banget karo koe mas.",
"Mbok ojo dadi wong sing nganyeli.",
"Teles kebes netes eluh neng dadaku.",
"Aku sayang karo koe beb, tapi ngapusi",
"Sedih aku. Lagi mangan iwakku malah dicolong pitek"]
selection = st.segmented_control(
"Examples", options
)
# Prediction
if selection:
st.session_state.result = pipe(selection)
if user_input:
st.session_state.result = pipe(user_input)
# Display results if available
if st.session_state.result:
for res in st.session_state.result:
st.write("Prediction")
st.success(res['label'].capitalize())
st.write("Score")
st.success(round(res['score'], 4))