Spaces:
Runtime error
Runtime error
nurindahpratiwi
commited on
Commit
·
f05d2a8
1
Parent(s):
a6ff6ac
Add application file
Browse files
app.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Import library yang dibutuhkan
|
| 2 |
+
import streamlit as st
|
| 3 |
+
from transformers import pipeline
|
| 4 |
+
|
| 5 |
+
# Buat title pada web apps
|
| 6 |
+
st.title("Sentiment Analysis App")
|
| 7 |
+
st.markdown("You can input 8 different language: arabic, englisg, french, german, hindi, italian, portuguese, and spanish")
|
| 8 |
+
|
| 9 |
+
# Buat text input dari user
|
| 10 |
+
text = st.text_input("Enter text here", "I like langing academy course")
|
| 11 |
+
|
| 12 |
+
# Buat variabel pipeline yang berisi model
|
| 13 |
+
pipeline = pipeline(task='text-classification', model='cardiffnlp/twitter-xlm-roberta-base-sentiment-multilingual')
|
| 14 |
+
|
| 15 |
+
# Buat button predict
|
| 16 |
+
if st.button("Predict"):
|
| 17 |
+
result = pipeline(text)[0] # Menyimpan nilai predict pada variabel result
|
| 18 |
+
sentiment = result['label'] # Menyimpan nilai label pada variabel sentiment
|
| 19 |
+
score = result['score'] # Menyimpan nilai confidence score pada variabel score
|
| 20 |
+
st.write(f"Sentiment: {sentiment}")
|
| 21 |
+
# Jika score ada nilainya maka tampilkan scorenya
|
| 22 |
+
if score is not None:
|
| 23 |
+
st.write(f"Score: {score}")
|