-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGUI.py
68 lines (56 loc) · 1.88 KB
/
GUI.py
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
58
59
60
61
62
63
64
65
66
67
68
import numpy as np
import PySimpleGUI as sg
import tensorflow as tf
from Model_utils import *
from Load_Data import *
from tensorflow.keras.preprocessing import text, sequence
dummy_y = np.reshape(np.array([[1,0,0,0,0]]),(1,5 ))
sg.theme('BluePurple')
layout = [[sg.Text('Number of stars:'), sg.Text(size=(15,1), key='-OUTPUT-')],
[sg.Input(key='-IN-')],
[sg.Button('Show'), sg.Button('Exit')]]
window = sg.Window('Reviews2Stars', layout)
#Check points for step training_trial_step
checkpoint_path = "/home/enihcam/Downloads/github-repos/Reviews-To-Stars0/training_trial1"
'''
These parameters
1870
37637
10
'''
max_length = 1870
vocab_size = 25886
num_classes= 5
def preprocess(data):
tokenizer = text.Tokenizer(num_words=vocab_size)
tokenizer.fit_on_texts(data)
data_x = tokenizer.texts_to_sequences(data)
data_x = sequence.pad_sequences(data_x, maxlen=max_length)
data_x = np.array(data_x)
return data_x
data_x,_ = load_data('Reviews.csv')
out = Text_CNN(
sequence_length = max_length,
vocab_size = vocab_size,
num_classes = num_classes,
window_width = 128,
filter_sizes = [2,3,4],
num_filters = 2,
dropout = False
)
checkpoint_prefix = os.path.join(checkpoint_path,"ckpt")
train_saver = tf.train.Saver(max_to_keep=2)
with tf.Session() as sess:
train_saver.restore(sess,checkpoint_prefix)
while True: # Event Loop
event, values = window.read()
print(event, values)
if event == sg.WIN_CLOSED or event == 'Exit':
break
if event == 'Show':
# Update the "output" text element to be the value of "input" element
data = values['-IN-']
data = preprocess(data)
predictions = sess.run([out.predictions],feed_dict={out.input_x:data,out.input_y:dummy_y,out.dropout_prob:1})
window['-OUTPUT-'].update(str(predictions[0][0]+1)+' of 5')
window.close()