-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
63 lines (51 loc) · 1.72 KB
/
app.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
# -----------------------------------------------------------
# This module displays a window containing a search bar.
#
#
# (C) 2020 Muhammad Bilal Akmal, 17K-3669
# -----------------------------------------------------------
import PySimpleGUI as sg
from index_builder import generate_index_file
from query_dispatcher import dispatch_query
sg.theme('DarkBlue')
layout = [ [sg.Text('')],
[sg.Image(r'resources\icon.png'), sg.Text('BoonGiggle', font=('Helvetica', 18))],
[sg.Text('A Search Engine For Trump\'s Speeches.', font=('Helvetica', 9))],
[sg.Input(key='_QUERY_'), sg.Button('SEARCH')],
[sg.Text('')],
[sg.Text(size=(48,6), key='_DOCS_')],
[sg.Text('')],
[sg.Text(size=(4, 1), key='_SIZE_')],
[sg.Button('Build Index')],
[sg.Text('')]
]
window = sg.Window(
title='Information Retreival - Assignment 1',
layout=layout,
resizable=True,
element_padding=(4, 4),
element_justification='center'
)
while True:
event, values = window.read()
print(event, values)
if event is None:
break
if event == 'SEARCH':
query = values['_QUERY_']
if not query:
continue
result = dispatch_query(query)
if result == None:
display = 'No relevant speeches.'
size = 0
else:
display = ', '.join(result[0])
size = len(result[0])
print(f'Relevant speeches: {display}')
print(f'Number of relevant documents: {size}')
window['_DOCS_'].update(display)
window['_SIZE_'].update(size)
elif event == 'Build Index':
generate_index_file()
window.close()