File size: 1,422 Bytes
0c23360
 
5648f24
724d79b
 
541433e
724d79b
 
0c23360
541433e
5648f24
b984ea7
0c23360
541433e
b984ea7
0c23360
06bd1d2
541433e
0c23360
724d79b
 
 
 
 
 
 
 
541433e
724d79b
5648f24
 
b5a722d
 
0c23360
541433e
b5a722d
541433e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import streamlit as st
from transformers import pipeline
from transformers import AutoModelForSequenceClassification, AutoTokenizer
from googletrans import Translator

# Load the sentiment analysis model from our BERT model
classifier = pipeline("text-classification", model="MarieAngeA13/Sentiment-Analysis-BERT")
translator = Translator()

# Create a Streamlit app
st.title('Sentiment Analysis with BERT')
st.write('Enter some text and we will predict its sentiment!/Entrez un texte et nous prédirons son sentiment!')

# Add a text input box for the user to enter text
text_input = st.text_input('Enter text here/Saisir le texte ici')


# When the user submits text, run the sentiment analysis model on it
if st.button('Submit'):
    # Translate the text if the detected language is French
    detected_language = translator.detect(text_input).lang
    if detected_language == 'fr':
        translation = translator.translate(text_input, src='fr', dest='en')
        translated_text = translation.text
    else:
        translated_text = text_input

    # Predict the sentiment of the text using our own BERT model
    output = classifier(translated_text)

    best_prediction = output[0]
    sentiment = best_prediction['label']
    confidence = best_prediction['score']
    
    # Display the sentiment prediction to the user
    st.write(f'Sentiment: {sentiment}')
    st.write(f'Confidence: {round(confidence, 2)}')