-
Notifications
You must be signed in to change notification settings - Fork 0
/
pyva.py
58 lines (49 loc) · 1.83 KB
/
pyva.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
import os
import sys
import wolframalpha
import wikipedia
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from dotenv import load_dotenv
load_dotenv()
class MainWindow(QMainWindow):
def __init__(self, *args, **kwargs):
super(MainWindow, self).__init__(*args, **kwargs)
self.setWindowTitle("Python Virtual Assistant")
self.resize(550, 120)
label = QLabel(
"Hello, I am PyVA, the Python Virtual Assistant. How can I help you?")
label.setAlignment(Qt.AlignLeft)
label.setIndent(20)
self.setCentralWidget(label)
self.textbox = QLineEdit(self)
self.textbox.move(20, 20)
self.textbox.resize(500, 40)
self.button = QPushButton('Now search!', self)
self.button.move(20, 80)
self.button.clicked.connect(self.on_click)
self.show()
@pyqtSlot()
def on_click(self):
raw_input = self.textbox.text()
try:
# wolframalpha
app_id = os.getenv('WOLFRAM_ID')
client = wolframalpha.Client(app_id)
result = client.query(raw_input)
answer1 = next(result.results).text
QMessageBox.question(self, 'Results:',
f"You asked {raw_input}, apparently the answer is... " + answer1, QMessageBox.Ok, QMessageBox.Ok)
except StopIteration:
# wikipedia
wikipedia.set_lang("ES")
answer2 = wikipedia.summary(raw_input, sentences=3)
QMessageBox.question(self, 'Results:',
f"You asked {raw_input}, apparently the answer is... " + answer2, QMessageBox.Ok, QMessageBox.Ok)
self.textbox.setText("")
if __name__ == '__main__':
app = QApplication(sys.argv)
window = MainWindow()
window.show()
app.exec_()