Update app.py
Browse files
app.py
CHANGED
|
@@ -25,7 +25,6 @@ selected_model = st.sidebar.radio("Зачем пришел?", ("Классифи
|
|
| 25 |
"Генерация текста GPT-моделью по пользовательскому prompt"))
|
| 26 |
|
| 27 |
# Классификация отзыва на поликлиники
|
| 28 |
-
model_options = ["BagOfWords", "TF-IDF", "LSTM", "BERT-based-ru"]
|
| 29 |
if selected_model == "Классифиция отзывов лечебных учреждений":
|
| 30 |
st.title("""
|
| 31 |
Приложение классифицирует твой отзыв и подскажет позитивный он или негативный
|
|
@@ -83,46 +82,59 @@ if selected_model == "Классифиция отзывов лечебных у
|
|
| 83 |
# st.write(data)
|
| 84 |
st.table(data)
|
| 85 |
user_text_input = st.text_area('Введите ваш отзыв здесь:', '')
|
| 86 |
-
selected_model_name = st.selectbox('Выберите модель:', model_options, index=0)
|
| 87 |
|
| 88 |
if st.button('Предсказать'):
|
| 89 |
start_time = time.time()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
X = vectorizer_2.transform([data_preprocessing_hard(user_text_input)])
|
| 97 |
-
predictions = classifier_tf.predict(X)
|
| 98 |
-
|
| 99 |
-
elif selected_model_name == "LSTM":
|
| 100 |
-
predictions = predict_review(model=lstm, review_text=user_text_input, net_config=net_config,
|
| 101 |
-
vocab_to_int=vocab_to_int)
|
| 102 |
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
input_tensor = tensor(padded_tokens).unsqueeze(0)
|
| 107 |
-
with torch.no_grad():
|
| 108 |
-
outputs = model(input_tensor)
|
| 109 |
-
X = outputs.last_hidden_state[:,0,:].detach().cpu().numpy()
|
| 110 |
-
predictions = BERT_lin_cl.predict(X)
|
| 111 |
-
pass
|
| 112 |
-
|
| 113 |
end_time = time.time()
|
| 114 |
-
prediction_time
|
| 115 |
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
gif_url = 'https://i.gifer.com/LdC3.gif'
|
| 124 |
st.image(gif_url, caption="Негативный коментарий")
|
| 125 |
-
|
|
|
|
|
|
|
|
|
|
| 126 |
|
| 127 |
|
| 128 |
|
|
|
|
| 25 |
"Генерация текста GPT-моделью по пользовательскому prompt"))
|
| 26 |
|
| 27 |
# Классификация отзыва на поликлиники
|
|
|
|
| 28 |
if selected_model == "Классифиция отзывов лечебных учреждений":
|
| 29 |
st.title("""
|
| 30 |
Приложение классифицирует твой отзыв и подскажет позитивный он или негативный
|
|
|
|
| 82 |
# st.write(data)
|
| 83 |
st.table(data)
|
| 84 |
user_text_input = st.text_area('Введите ваш отзыв здесь:', '')
|
|
|
|
| 85 |
|
| 86 |
if st.button('Предсказать'):
|
| 87 |
start_time = time.time()
|
| 88 |
+
predictions = []
|
| 89 |
+
prediction_time = []
|
| 90 |
+
X = vectorizer_1.transform([data_preprocessing_hard(user_text_input)])
|
| 91 |
+
predictions.append(classifier_bag.predict(X))
|
| 92 |
+
end_time = time.time()
|
| 93 |
+
prediction_time.append(end_time - start_time)
|
| 94 |
|
| 95 |
+
start_time = time.time()
|
| 96 |
+
X1 = vectorizer_2.transform([data_preprocessing_hard(user_text_input)])
|
| 97 |
+
predictions.append(classifier_tf.predict(X1))
|
| 98 |
+
end_time = time.time()
|
| 99 |
+
prediction_time.append(end_time - start_time)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
|
| 101 |
+
start_time = time.time()
|
| 102 |
+
predictions.append(predict_review(model=lstm, review_text=user_text_input, net_config=net_config,
|
| 103 |
+
vocab_to_int=vocab_to_int))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
end_time = time.time()
|
| 105 |
+
prediction_time.append(end_time - start_time)
|
| 106 |
|
| 107 |
+
tokens = tokenizer.encode(user_text_input, add_special_tokens=True)
|
| 108 |
+
padded_tokens = tokens + [0] * (MAX_LEN - len(tokens))
|
| 109 |
+
input_tensor = tensor(padded_tokens).unsqueeze(0)
|
| 110 |
+
with torch.no_grad():
|
| 111 |
+
outputs = model(input_tensor)
|
| 112 |
+
X2 = outputs.last_hidden_state[:,0,:].detach().cpu().numpy()
|
| 113 |
+
predictions.append(BERT_lin_cl.predict(X2))
|
| 114 |
+
end_time = time.time()
|
| 115 |
+
prediction_time.append(end_time - start_time)
|
| 116 |
+
|
| 117 |
+
res = []
|
| 118 |
+
for i in predictions:
|
| 119 |
+
if i >= 0.5:
|
| 120 |
+
res.append('Позитивный комментарий')
|
| 121 |
+
else:
|
| 122 |
+
res.append('Негативный комментарий')
|
| 123 |
+
|
| 124 |
+
result = pd.DataFrame({
|
| 125 |
+
'Модель': ["BagOfWords", "TF-IDF", "LSTM", "BERT-based-ru"],
|
| 126 |
+
'Результат': res,
|
| 127 |
+
'Время предсказания' : prediction_time
|
| 128 |
+
})
|
| 129 |
+
st.table(result)
|
| 130 |
+
|
| 131 |
+
if len(result[result['Результат'] == 'Негативный комментарий']) >= 2:
|
| 132 |
gif_url = 'https://i.gifer.com/LdC3.gif'
|
| 133 |
st.image(gif_url, caption="Негативный коментарий")
|
| 134 |
+
|
| 135 |
+
else:
|
| 136 |
+
gif_url = 'https://media2.giphy.com/media/v1.Y2lkPTc5MGI3NjExOTdnYjJ1eTE0bjRuMGptcjhpdTk2YTYzeXEzMzlidWFsamY2bW8wZyZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/LUg1GEjapflW7Vg6B9/giphy.gif'
|
| 137 |
+
st.image(gif_url, caption="Позитивный коментарий")
|
| 138 |
|
| 139 |
|
| 140 |
|