PIERRE CUGNET
commited on
Commit
•
57410b1
1
Parent(s):
3ba964c
feat(py): add a button to prevent automatic inference
Browse files
app.py
CHANGED
@@ -52,6 +52,7 @@ def clean_text(text):
|
|
52 |
|
53 |
st.title('Welcome to my twitter airline sentiment analysis !', anchor='center')
|
54 |
airline_tweet = st.text_input('Enter your english airline tweet here, press enter, and wait for the model to predict the sentiment of your review:', '@AmericanAirline My flight was great! :)')
|
|
|
55 |
tokenizer = AutoTokenizer.from_pretrained('distilbert-base-uncased', num_labels=2)
|
56 |
|
57 |
encoded_input = tokenizer(
|
@@ -83,13 +84,16 @@ y = Dense(2, activation = 'softmax')(out) #Here 2 because we got 2 categories to
|
|
83 |
model = tf.keras.Model(inputs=bert_inputs, outputs=y)
|
84 |
|
85 |
model.load_weights('sentiment_weights.h5')
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
if
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
|
|
|
|
|
|
95 |
|
|
|
52 |
|
53 |
st.title('Welcome to my twitter airline sentiment analysis !', anchor='center')
|
54 |
airline_tweet = st.text_input('Enter your english airline tweet here, press enter, and wait for the model to predict the sentiment of your review:', '@AmericanAirline My flight was great! :)')
|
55 |
+
|
56 |
tokenizer = AutoTokenizer.from_pretrained('distilbert-base-uncased', num_labels=2)
|
57 |
|
58 |
encoded_input = tokenizer(
|
|
|
84 |
model = tf.keras.Model(inputs=bert_inputs, outputs=y)
|
85 |
|
86 |
model.load_weights('sentiment_weights.h5')
|
87 |
+
|
88 |
+
st.button('Predict sentiment')
|
89 |
+
|
90 |
+
if st.button('Predict sentiment'):
|
91 |
+
prediction = model.predict({'input_ids': encoded_input['input_ids'], 'input_mask': encoded_input['attention_mask']})
|
92 |
+
encoded_dict = {0: 'negative', 1: 'positive'}
|
93 |
+
if np.argmax(prediction) == 0:
|
94 |
+
st.write(f'Sentiment predicted : {encoded_dict[np.argmax(prediction)]}')
|
95 |
+
st.write(f'I\'m sorry you had a bad experience with our company :( , please accept our apologies')
|
96 |
+
else:
|
97 |
+
st.write(f'Sentiment predicted : {encoded_dict[np.argmax(prediction)]}')
|
98 |
+
st.write('Glad your flight was good ! Hope to see you soon :)')
|
99 |
|