sunny-annie commited on
Commit
cc0a3af
·
1 Parent(s): 0724714
Files changed (1) hide show
  1. main.py +56 -0
main.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import torch
3
+ import time
4
+ from models.model_rnn import func
5
+ from models.model_ml import final
6
+ from models.LSTM_model import data_preprocessing, padding, preprocess_single_string, sentimentLSTM, load_model, predict_sentiment
7
+ from models.bert_func import load_bert_lr_model, prediction
8
+ import numpy as np
9
+
10
+
11
+ device = 'cuda' if torch.cuda.is_available() else 'cpu'
12
+
13
+ txt_label = 'Enter review text'
14
+ txt = st.text_area(label=txt_label, height=200)
15
+
16
+ with st.form('button'):
17
+ button_click = st.form_submit_button("Get result")
18
+
19
+ col1, col2, col3, col4 = st.columns(4)
20
+
21
+ with col1: # ML
22
+ st.write('ML model')
23
+ if button_click:
24
+ t = time.process_time()
25
+ output = final(txt)
26
+ elapsed_time = time.process_time() - t
27
+ st.write('`Negative review`' if np.around(output, 0) == 0 else '`Positive review`')
28
+ st.write('`Time elapsed :`', round(elapsed_time, 3))
29
+
30
+ with col2: # RNN
31
+ st.write('RNN model')
32
+ if button_click:
33
+ t = time.process_time()
34
+ output = func(txt)
35
+ elapsed_time = time.process_time() - t
36
+ st.write('`Negative review`' if np.around(output, 0) == 0 else '`Positive review`')
37
+ st.write('`Time elapsed :`', round(elapsed_time, 3))
38
+
39
+ with col3: # LSTM
40
+ st.write('LSTM model')
41
+ if button_click:
42
+ st.write(f'`{predict_sentiment(txt)}`')
43
+ t = time.process_time()
44
+ elapsed_time = time.process_time() - t
45
+ st.write('`Time elapsed :`', round(elapsed_time, 3))
46
+
47
+
48
+ model, tokenizer, lr = load_bert_lr_model('models/bert_lr.joblib')
49
+
50
+ with col4: # BERT
51
+ st.write('BERT')
52
+ if button_click:
53
+ t = time.process_time()
54
+ st.write(f'`{prediction(txt, model, tokenizer, lr)}`')
55
+ elapsed_time = time.process_time() - t
56
+ st.write('`Time elapsed :`', round(elapsed_time, 3))