MarieAngeA13
commited on
Commit
·
06bd1d2
1
Parent(s):
20bbaa8
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,8 @@
|
|
1 |
import streamlit as st
|
2 |
from transformers import pipeline
|
3 |
from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
|
|
|
|
4 |
|
5 |
# Load the sentiment analysis model from our BERT model
|
6 |
classifier = pipeline("text-classification", model = "MarieAngeA13/Sentiment-Analysis-BERT")
|
@@ -10,12 +12,24 @@ st.title('Sentiment Analysis with BERT')
|
|
10 |
st.write('Enter some text and we will predict its sentiment!')
|
11 |
|
12 |
# Add a text input box for the user to enter text
|
|
|
13 |
text_input = st.text_input('Enter text here')
|
14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
# When the user submits text, run the sentiment analysis model on it
|
16 |
if st.button('Submit'):
|
17 |
# Predict the sentiment of the text using our own BERT model
|
18 |
-
output = classifier(
|
19 |
|
20 |
best_prediction = output[0]
|
21 |
sentiment = best_prediction['label']
|
@@ -24,4 +38,4 @@ if st.button('Submit'):
|
|
24 |
# Display the sentiment prediction to the user
|
25 |
st.write(f'Sentiment: {sentiment}')
|
26 |
st.write(f'Confidence: {round(confidence, 2)}')
|
27 |
-
|
|
|
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")
|
|
|
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']
|
|
|
38 |
# Display the sentiment prediction to the user
|
39 |
st.write(f'Sentiment: {sentiment}')
|
40 |
st.write(f'Confidence: {round(confidence, 2)}')
|
41 |
+
|