Spaces:
Sleeping
Sleeping
File size: 901 Bytes
2cec43b 552acce 2cec43b 552acce 2cec43b 3c12279 2cec43b |
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 |
import streamlit as st
from transformers import pipeline
# title
st.title("Sentiment Analysis App")
st.markdown("You can input 8 different language: arabic, english, french, german, hindi, italian, portuguese, spanish")
# text input
text = st.text_input("Enter text here", "I love you")
# Model initiate
model = "cardiffnlp/twitter-xlm-roberta-base-sentiment-multilingual"
# Sentiment analysis function
def analyze_sentiment(text, model):
if model == "cardiffnlp/twitter-xlm-roberta-base-sentiment-multilingual":
classifier = pipeline("sentiment-analysis", model=model)
result = classifier(text)[0]
sentiment = result['label']
score = result['score']
return sentiment, score
if st.button("Analyze"):
sentiment, score = analyze_sentiment(text, model)
st.write(f"Sentiment: {sentiment}")
if score is not None:
st.write(f"Score: {score}") |