File size: 983 Bytes
f05d2a8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# Import library yang dibutuhkan
import streamlit as st
from transformers import pipeline

# Buat title pada web apps
st.title("Sentiment Analysis App")
st.markdown("You can input 8 different language: arabic, englisg, french, german, hindi, italian, portuguese, and spanish")

# Buat text input dari user
text = st.text_input("Enter text here", "I like langing academy course")

# Buat variabel pipeline yang berisi model
pipeline = pipeline(task='text-classification', model='cardiffnlp/twitter-xlm-roberta-base-sentiment-multilingual')

# Buat button predict
if st.button("Predict"):
    result = pipeline(text)[0] # Menyimpan nilai predict pada variabel result
    sentiment = result['label'] # Menyimpan nilai label pada variabel sentiment
    score = result['score'] # Menyimpan nilai confidence score pada variabel score
    st.write(f"Sentiment: {sentiment}")
    # Jika score ada nilainya maka tampilkan scorenya
    if score is not None:
        st.write(f"Score: {score}")