-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathstart.py
221 lines (158 loc) · 5.54 KB
/
start.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
import os
import platform
import sys
import webbrowser
def start_api():
try:
from .api import start_api
start_api(api=True)
except:
raise Exception(
"API could not be started, please install gpt-computer-agent[api]"
)
def start(api=False):
if api:
return start_api()
from PyQt5.QtWidgets import QApplication
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import QSystemTrayIcon, QMenu, QAction
from PyQt5.QtCore import Qt
from pynput import keyboard
"""
Starts the computer agent application.
This function starts the computer agent application, which includes parsing command-line arguments
to set the profile, initializing the graphical user interface, and starting the application event loop.
Command-line Arguments:
--profile (str): The profile to use for the application.
Raises:
ImportError: If the required modules or packages are not found.
Returns:
None
"""
try:
pass
except:
pass
# get --profile argument with library
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("--profile", help="profile to use")
parser.add_argument("--api", help="Enable API mode", action="store_true")
parser.add_argument("--set_tts_provider", help="Set tts provider only")
parser.add_argument("--set_stt_provider", help="Set stt provider only")
parser.add_argument("--set_llm", help="Set llm model only")
args = parser.parse_args()
set_tts_provider = args.set_tts_provider
if set_tts_provider is not None:
from .utils.db import save_tts_model_settings
save_tts_model_settings(set_tts_provider)
return
set_stt_provider = args.set_stt_provider
if set_stt_provider is not None:
from .utils.db import save_stt_model_settings
save_stt_model_settings(set_stt_provider)
return
set_llm = args.set_llm
if set_llm is not None:
from .utils.db import save_model_settings
save_model_settings(set_llm)
return
profile = args.profile
api_arg = args.api
print("Profile:", profile)
if profile is not None:
from .utils.db import set_profile
set_profile(profile)
try:
from .utils.db import (
load_tts_model_settings,
load_stt_model_settings,
is_logo_active_setting_active,
load_logo_file_path,
)
except ImportError:
from utils.db import (
load_tts_model_settings,
load_stt_model_settings,
load_logo_file_path,
)
if load_tts_model_settings() != "openai":
from .audio.tts_providers.microsoft_local import preload_tts_microsoft_local
preload_tts_microsoft_local()
if load_stt_model_settings() != "openai":
from .audio.stt_providers.openai_whisper_local import (
preload_stt_openai_whisper_local,
)
preload_stt_openai_whisper_local()
try:
from .gpt_computer_agent import MainWindow
except ImportError:
from gpt_computer_agent import MainWindow
os.environ["QT_AUTO_SCREEN_SCALE_FACTOR"] = "1"
if api or api_arg:
print("API Enabled")
MainWindow.api_enabled = True
app = QApplication(sys.argv)
ex = MainWindow()
from PyQt5 import QtGui
from PyQt5 import QtCore
app_icon = QtGui.QIcon()
app_icon.addFile(load_logo_file_path(), QtCore.QSize(48, 48))
app.setWindowIcon(app_icon)
ex.the_app = app
# Create the tray
menu_icon = QtGui.QIcon()
menu_icon.addFile(load_logo_file_path(), QtCore.QSize(48, 48))
menu_active_icon = QtGui.QIcon()
menu_active_icon.addFile(load_logo_file_path(), QtCore.QSize(48, 48))
tray = QSystemTrayIcon()
tray.setIcon(menu_icon)
tray.setVisible(True)
ex.tray = tray
ex.tray_active_icon = menu_active_icon
ex.tray_icon = menu_icon
# Create the menu
menu = QMenu()
ex.the_tray = tray
show_menu = QAction("Show")
def show_menu_connect():
ex.setWindowState(Qt.WindowNoState)
show_menu.triggered.connect(show_menu_connect)
menu.addAction(show_menu)
hide_menu = QAction("Hide")
hide_menu.triggered.connect(ex.showMinimized)
menu.addAction(hide_menu)
menu.addSeparator()
if platform.system() == "Darwin":
the_text_of_screenshot_and_microphone = (
"Action: ⌃+⌥+⌘+up Screenshot and Microphone"
)
else:
the_text_of_screenshot_and_microphone = (
"Action: ctrl+alt+windows+up Screenshot and Microphone"
)
screenshot_and_microphone = QAction(the_text_of_screenshot_and_microphone)
def screenshot_and_microphone_connect():
ex.setWindowState(Qt.WindowNoState)
ex.screenshot_and_microphone_button_action()
screenshot_listener = keyboard.GlobalHotKeys(
{"<ctrl>+<alt>+<cmd>+<up>": screenshot_and_microphone_connect}
)
screenshot_listener.start()
screenshot_and_microphone.triggered.connect(screenshot_and_microphone_connect)
menu.addAction(screenshot_and_microphone)
menu.addSeparator()
action = QAction("Open GitHub Issues")
action.triggered.connect(
lambda: webbrowser.open(
"https://github.com/khulnasoft/gpt-computer-agent/issues"
)
)
menu.addAction(action)
# Add a Quit option to the menu.
quit = QAction("Quit")
quit.triggered.connect(app.quit)
menu.addAction(quit)
# Add the menu to the tray
tray.setContextMenu(menu)
sys.exit(app.exec_())