Commit
·
8d97474
1
Parent(s):
06bd1d2
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,41 +1,42 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
from transformers import pipeline
|
| 3 |
from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
| 4 |
-
pip install googletrans==4.0.0rc1
|
| 5 |
from googletrans import Translator
|
| 6 |
|
| 7 |
-
#
|
| 8 |
-
|
| 9 |
|
| 10 |
-
#
|
|
|
|
|
|
|
|
|
|
| 11 |
st.title('Sentiment Analysis with BERT')
|
| 12 |
st.write('Enter some text and we will predict its sentiment!')
|
| 13 |
|
| 14 |
-
#
|
| 15 |
translator = Translator()
|
| 16 |
text_input = st.text_input('Enter text here')
|
| 17 |
|
|
|
|
| 18 |
detected_language = translator.detect(text_input).lang
|
| 19 |
|
|
|
|
| 20 |
if detected_language == 'fr':
|
| 21 |
translation = translator.translate(text_input, src='fr', dest='en')
|
| 22 |
translated_text = translation.text
|
| 23 |
else:
|
| 24 |
translated_text = text_input
|
| 25 |
-
|
| 26 |
-
|
| 27 |
|
| 28 |
-
|
| 29 |
-
# When the user submits text, run the sentiment analysis model on it
|
| 30 |
if st.button('Submit'):
|
| 31 |
-
#
|
| 32 |
output = classifier(translated_text)
|
| 33 |
|
| 34 |
best_prediction = output[0]
|
| 35 |
sentiment = best_prediction['label']
|
| 36 |
confidence = best_prediction['score']
|
| 37 |
|
| 38 |
-
#
|
| 39 |
st.write(f'Sentiment: {sentiment}')
|
| 40 |
st.write(f'Confidence: {round(confidence, 2)}')
|
| 41 |
-
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from transformers import pipeline
|
| 3 |
from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
|
|
|
| 4 |
from googletrans import Translator
|
| 5 |
|
| 6 |
+
# Installer le package googletrans
|
| 7 |
+
!pip install googletrans==4.0.0rc1
|
| 8 |
|
| 9 |
+
# Charger le modèle de classification des sentiments BERT
|
| 10 |
+
classifier = pipeline("text-classification", model="MarieAngeA13/Sentiment-Analysis-BERT")
|
| 11 |
+
|
| 12 |
+
# Créer une application Streamlit
|
| 13 |
st.title('Sentiment Analysis with BERT')
|
| 14 |
st.write('Enter some text and we will predict its sentiment!')
|
| 15 |
|
| 16 |
+
# Ajouter un champ de saisie de texte pour l'utilisateur
|
| 17 |
translator = Translator()
|
| 18 |
text_input = st.text_input('Enter text here')
|
| 19 |
|
| 20 |
+
# Détecter la langue du texte saisi
|
| 21 |
detected_language = translator.detect(text_input).lang
|
| 22 |
|
| 23 |
+
# Traduire le texte s'il est en français
|
| 24 |
if detected_language == 'fr':
|
| 25 |
translation = translator.translate(text_input, src='fr', dest='en')
|
| 26 |
translated_text = translation.text
|
| 27 |
else:
|
| 28 |
translated_text = text_input
|
| 29 |
+
st.write(translated_text)
|
|
|
|
| 30 |
|
| 31 |
+
# Lorsque l'utilisateur clique sur "Submit"
|
|
|
|
| 32 |
if st.button('Submit'):
|
| 33 |
+
# Prédire le sentiment du texte en utilisant notre modèle BERT
|
| 34 |
output = classifier(translated_text)
|
| 35 |
|
| 36 |
best_prediction = output[0]
|
| 37 |
sentiment = best_prediction['label']
|
| 38 |
confidence = best_prediction['score']
|
| 39 |
|
| 40 |
+
# Afficher la prédiction de sentiment à l'utilisateur
|
| 41 |
st.write(f'Sentiment: {sentiment}')
|
| 42 |
st.write(f'Confidence: {round(confidence, 2)}')
|
|
|