MarieAngeA13
commited on
Commit
·
541433e
1
Parent(s):
8d97474
Update app.py
Browse files
app.py
CHANGED
@@ -1,42 +1,40 @@
|
|
1 |
import streamlit as st
|
2 |
from transformers import pipeline
|
3 |
from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
|
|
4 |
from googletrans import Translator
|
5 |
|
6 |
-
#
|
7 |
-
|
8 |
|
9 |
-
#
|
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 |
-
#
|
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 |
-
|
|
|
|
|
30 |
|
31 |
-
#
|
32 |
if st.button('Submit'):
|
33 |
-
#
|
34 |
output = classifier(translated_text)
|
35 |
|
36 |
best_prediction = output[0]
|
37 |
sentiment = best_prediction['label']
|
38 |
confidence = best_prediction['score']
|
39 |
|
40 |
-
#
|
41 |
st.write(f'Sentiment: {sentiment}')
|
42 |
-
st.write(f'Confidence: {round(confidence, 2)}')
|
|
|
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 |
+
# Load the sentiment analysis model from our BERT model
|
8 |
+
classifier = pipeline("text-classification", model = "MarieAngeA13/Sentiment-Analysis-BERT")
|
9 |
|
10 |
+
# Create a Streamlit app
|
|
|
|
|
|
|
11 |
st.title('Sentiment Analysis with BERT')
|
12 |
st.write('Enter some text and we will predict its sentiment!')
|
13 |
|
14 |
+
# Add a text input box for the user to enter text
|
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 |
+
print(translated_text)
|
26 |
+
|
27 |
+
|
28 |
|
29 |
+
# When the user submits text, run the sentiment analysis model on it
|
30 |
if st.button('Submit'):
|
31 |
+
# Predict the sentiment of the text using our own BERT model
|
32 |
output = classifier(translated_text)
|
33 |
|
34 |
best_prediction = output[0]
|
35 |
sentiment = best_prediction['label']
|
36 |
confidence = best_prediction['score']
|
37 |
|
38 |
+
# Display the sentiment prediction to the user
|
39 |
st.write(f'Sentiment: {sentiment}')
|
40 |
+
st.write(f'Confidence: {round(confidence, 2)}')
|