Spaces:
Sleeping
Sleeping
| 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}") |