File size: 1,453 Bytes
0c23360 5648f24 06bd1d2 7e10d9c 8d97474 0c23360 8d97474 5648f24 0c23360 8d97474 06bd1d2 0c23360 8d97474 06bd1d2 8d97474 06bd1d2 8d97474 06bd1d2 8d97474 0c23360 8d97474 06bd1d2 5648f24 b5a722d 0c23360 8d97474 b5a722d 20bbaa8 |
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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
import streamlit as st
from transformers import pipeline
from transformers import AutoModelForSequenceClassification, AutoTokenizer
from googletrans import Translator
# Installer le package googletrans
!pip install googletrans==4.0.0rc1
# Charger le modèle de classification des sentiments BERT
classifier = pipeline("text-classification", model="MarieAngeA13/Sentiment-Analysis-BERT")
# Créer une application Streamlit
st.title('Sentiment Analysis with BERT')
st.write('Enter some text and we will predict its sentiment!')
# Ajouter un champ de saisie de texte pour l'utilisateur
translator = Translator()
text_input = st.text_input('Enter text here')
# Détecter la langue du texte saisi
detected_language = translator.detect(text_input).lang
# Traduire le texte s'il est en français
if detected_language == 'fr':
translation = translator.translate(text_input, src='fr', dest='en')
translated_text = translation.text
else:
translated_text = text_input
st.write(translated_text)
# Lorsque l'utilisateur clique sur "Submit"
if st.button('Submit'):
# Prédire le sentiment du texte en utilisant notre modèle BERT
output = classifier(translated_text)
best_prediction = output[0]
sentiment = best_prediction['label']
confidence = best_prediction['score']
# Afficher la prédiction de sentiment à l'utilisateur
st.write(f'Sentiment: {sentiment}')
st.write(f'Confidence: {round(confidence, 2)}')
|