|
import streamlit as st |
|
from transformers import pipeline |
|
from transformers import AutoModelForSequenceClassification, AutoTokenizer |
|
from googletrans import Translator |
|
|
|
|
|
classifier = pipeline("text-classification", model="MarieAngeA13/Sentiment-Analysis-BERT") |
|
translator = Translator() |
|
|
|
|
|
st.title('Sentiment Analysis with BERT') |
|
st.write('Enter some text and we will predict its sentiment!/Entrez un texte et nous prédirons son sentiment!') |
|
|
|
|
|
text_input = st.text_input('Enter text here/Saisir le texte ici') |
|
|
|
|
|
|
|
if st.button('Submit'): |
|
|
|
detected_language = translator.detect(text_input).lang |
|
if detected_language == 'fr': |
|
translation = translator.translate(text_input, src='fr', dest='en') |
|
translated_text = translation.text |
|
else: |
|
translated_text = text_input |
|
|
|
|
|
output = classifier(translated_text) |
|
|
|
best_prediction = output[0] |
|
sentiment = best_prediction['label'] |
|
confidence = best_prediction['score'] |
|
|
|
|
|
st.write(f'Sentiment: {sentiment}') |
|
st.write(f'Confidence: {round(confidence, 2)}') |