MarieAngeA13
commited on
Commit
•
724d79b
1
Parent(s):
3d91c59
Update app.py
Browse files
app.py
CHANGED
@@ -1,8 +1,11 @@
|
|
1 |
import streamlit as st
|
2 |
from transformers import pipeline
|
3 |
from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
|
|
|
|
4 |
# Load the sentiment analysis model from our BERT model
|
5 |
-
classifier = pipeline("text-classification", model
|
|
|
6 |
|
7 |
# Create a Streamlit app
|
8 |
st.title('Sentiment Analysis with BERT')
|
@@ -14,8 +17,16 @@ 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']
|
|
|
1 |
import streamlit as st
|
2 |
from transformers import pipeline
|
3 |
from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
4 |
+
from googletrans import Translator
|
5 |
+
|
6 |
# Load the sentiment analysis model from our BERT model
|
7 |
+
classifier = pipeline("text-classification", model="MarieAngeA13/Sentiment-Analysis-BERT")
|
8 |
+
translator = Translator()
|
9 |
|
10 |
# Create a Streamlit app
|
11 |
st.title('Sentiment Analysis with BERT')
|
|
|
17 |
|
18 |
# When the user submits text, run the sentiment analysis model on it
|
19 |
if st.button('Submit'):
|
20 |
+
# Translate the text if the detected language is French
|
21 |
+
detected_language = translator.detect(text_input).lang
|
22 |
+
if detected_language == 'fr':
|
23 |
+
translation = translator.translate(text_input, src='fr', dest='en')
|
24 |
+
translated_text = translation.text
|
25 |
+
else:
|
26 |
+
translated_text = text_input
|
27 |
+
|
28 |
# Predict the sentiment of the text using our own BERT model
|
29 |
+
output = classifier(translated_text)
|
30 |
|
31 |
best_prediction = output[0]
|
32 |
sentiment = best_prediction['label']
|