forked from amaze18/allGPT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gui.py
107 lines (85 loc) · 3.26 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import sys
from PyQt6.QtCore import Qt, QRunnable, QThreadPool
from PyQt6.QtWidgets import (
QApplication,
QWidget,
QVBoxLayout,
QHBoxLayout,
QLineEdit,
QTextEdit,
QLabel,
QPushButton,
QFileDialog,
QMessageBox,
QStyleFactory,
)
import privateGPT
class QueryRunnable(QRunnable):
def __init__(self, query, callback):
super().__init__()
self.query = query
self.callback = callback
def run(self):
privateGPT.answer_query(self.query, self.callback)
class MainWindow(QWidget):
def __init__(self):
super().__init__()
self.init_ui()
def init_ui(self):
self.setWindowTitle('PrivateGPT')
main_layout = QVBoxLayout()
main_layout.setContentsMargins(20, 20, 20, 20)
button_layout = QHBoxLayout()
self.query_input = QLineEdit()
self.query_input.setPlaceholderText("Enter a query")
self.query_input.setEnabled(True)
self.query_input.setMinimumHeight(30)
button_layout.addWidget(self.query_input)
self.submit_button = QPushButton("Submit Query")
self.submit_button.clicked.connect(self.process_query)
self.submit_button.setEnabled(True)
self.submit_button.setMinimumHeight(30)
button_layout.addWidget(self.submit_button)
self.reset_button = QPushButton("ResetThis application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.
")
self.reset_button.clicked.connect(self.reset_query)
self.reset_button.setMinimumHeight(30)
button_layout.addWidget(self.reset_button)
main_layout.addLayout(button_layout)
self.answer_label = QLabel("Answer:")
main_layout.addWidget(self.answer_label)
self.answer_output = QTextEdit()
self.answer_output.setReadOnly(True)
self.answer_output.setVerticalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAsNeeded)
self.answer_output.setMinimumHeight(300)
main_layout.addWidget(self.answer_output)
self.setLayout(main_layout)
self.setMinimumSize(600,500)
def update_answer_output(self, answer, docs):
self.answer_output.insertPlainText(f"Answer: {answer}\n\n")
self.answer_output.insertPlainText("Sources:\n")
for document in docs:
source_name = document.metadata["source"]
page_content = document.page_content
self.answer_output.insertPlainText(f"- {source_name}:\n{page_content}\n\n")
self.answer_output.insertPlainText("\n\n")
self.answer_output.ensureCursorVisible()
def process_query(self):
query = self.query_input.text()
if query:
self.answer_output.insertPlainText(f"Query: {query}\n")
answer, docs = privateGPT.answer_query(query)
self.update_answer_output(answer, docs)
else:
self.answer_output.setPlainText("Please enter a valid query.")
def reset_query(self):
self.query_input.clear()
self.answer_output.clear()
def run_app():
app = QApplication(sys.argv)
app.setStyle(QStyleFactory.create('Fusion'))
main_window = MainWindow()
main_window.show()
sys.exit(app.exec())
if __name__ == "__main__":
run_app()