File size: 1,839 Bytes
cc0a3af
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import streamlit as st
import torch
import time
from models.model_rnn import func
from models.model_ml import final
from models.LSTM_model import data_preprocessing, padding, preprocess_single_string, sentimentLSTM, load_model, predict_sentiment
from models.bert_func import load_bert_lr_model, prediction
import numpy as np


device = 'cuda' if torch.cuda.is_available() else 'cpu'

txt_label = 'Enter review text'
txt = st.text_area(label=txt_label, height=200)
    
with st.form('button'):
    button_click = st.form_submit_button("Get result")    

col1, col2, col3, col4 = st.columns(4)

with col1: # ML
    st.write('ML model')
    if button_click:
        t = time.process_time()
        output = final(txt)
        elapsed_time = time.process_time() - t
        st.write('`Negative review`' if np.around(output, 0) == 0 else '`Positive review`')
        st.write('`Time elapsed :`', round(elapsed_time, 3))

with col2: # RNN
    st.write('RNN model')
    if button_click:
        t = time.process_time()
        output = func(txt)
        elapsed_time = time.process_time() - t
        st.write('`Negative review`' if np.around(output, 0) == 0 else '`Positive review`')
        st.write('`Time elapsed :`', round(elapsed_time, 3))

with col3: # LSTM
    st.write('LSTM model')
    if button_click:
        st.write(f'`{predict_sentiment(txt)}`')
        t = time.process_time()
        elapsed_time = time.process_time() - t
        st.write('`Time elapsed :`', round(elapsed_time, 3))
        
    
model, tokenizer, lr = load_bert_lr_model('models/bert_lr.joblib')

with col4: # BERT
    st.write('BERT')
    if button_click:
        t = time.process_time()
        st.write(f'`{prediction(txt, model, tokenizer, lr)}`')
        elapsed_time = time.process_time() - t
        st.write('`Time elapsed :`', round(elapsed_time, 3))