nurindahpratiwi
Add application file
f05d2a8
raw
history blame contribute delete
983 Bytes
# 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}")