MarieAngeA13 commited on
Commit
29ef367
·
1 Parent(s): d2f5783

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -1
app.py CHANGED
@@ -1,6 +1,7 @@
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,13 +11,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
 
16
  # When the user submits text, run the sentiment analysis model on it
17
  if st.button('Submit'):
18
  # Predict the sentiment of the text using our own BERT model
19
- output = classifier(text_input)
20
 
21
  best_prediction = output[0]
22
  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")
 
11
  st.write('Enter some text and we will predict its sentiment!')
12
 
13
  # Add a text input box for the user to enter text
14
+ translator = Translator()
15
  text_input = st.text_input('Enter text here')
16
 
17
+ detected_language = translator.detect(text_input).lang
18
+
19
+ if detected_language == 'fr':
20
+ translation = translator.translate(text_input, src='fr', dest='en')
21
+ translated_text = translation.text
22
+ else:
23
+ translated_text = text_input
24
+ print(translated_text)
25
+
26
+
27
 
28
  # When the user submits text, run the sentiment analysis model on it
29
  if st.button('Submit'):
30
  # Predict the sentiment of the text using our own BERT model
31
+ output = classifier(translated_text)
32
 
33
  best_prediction = output[0]
34
  sentiment = best_prediction['label']