Spaces:
Runtime error
Runtime error
File size: 11,768 Bytes
9b674e9 |
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 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 |
from PyQt5.QtWidgets import QDialog, QVBoxLayout, QLabel, QLineEdit, QPushButton
from PyQt5.QtCore import Qt
from ..utils.db import *
from ..agent.chat_history import clear_chat_history
def settings_popup(self):
"""
Display a settings popup dialog for configuring various options.
This function creates a settings dialog with options to reset chat history, enable/disable the just text model,
and change the active profile.
Parameters:
- self: Reference to the main application window.
Returns:
- None
"""
from ..gpt_computer_assistant import the_main_window
settings_dialog = QDialog()
settings_dialog.setWindowTitle("Settings")
settings_dialog.setWindowModality(Qt.ApplicationModal)
settings_dialog.setLayout(QVBoxLayout())
reset_memory_button = QPushButton("Reset Memory")
def clear_chat_history_():
"""
Clear the chat history and update the main window.
This function clears the chat history and updates the main window with a notification.
Returns:
- None
"""
clear_chat_history()
the_main_window.update_from_thread("Cleared Chat History")
settings_dialog.close()
reset_memory_button.clicked.connect(clear_chat_history_)
settings_dialog.layout().addWidget(reset_memory_button)
just_text_button = QPushButton("Enable Just Text Model")
settings_dialog.layout().addWidget(just_text_button)
if is_just_text_model_active():
just_text_button.setText("Disable Just Text Model")
def deactivate_just_text_model_():
"""
Deactivate the just text model and update the main window.
This function deactivates the just text model and updates the main window with a notification.
Returns:
- None
"""
deactivate_just_text_model()
the_main_window.update_from_thread("Disabled Just Text Model")
settings_dialog.close()
just_text_button.clicked.connect(deactivate_just_text_model_)
else:
def activate_just_text_model_():
"""
Activate the just text model and update the main window.
This function activates the just text model and updates the main window with a notification.
Returns:
- None
"""
activate_just_text_model()
the_main_window.update_from_thread("Enabled Just Text Model")
settings_dialog.close()
just_text_button.clicked.connect(activate_just_text_model_)
settings_dialog.layout().addWidget(QLabel("Profile"))
profile_input = QLineEdit()
profile_input.setText(get_profile())
settings_dialog.layout().addWidget(profile_input)
profile_save_button = QPushButton("Save")
def set_profile_(profile):
"""
Set the active profile and update the main window.
This function sets the active profile based on user input and updates the main window with a notification.
Parameters:
- profile (str): The profile name to set.
Returns:
- None
"""
set_profile(profile)
the_main_window.update_from_thread("Saved Profile")
settings_dialog.close()
profile_save_button.clicked.connect(lambda: set_profile_(profile_input.text()))
settings_dialog.layout().addWidget(profile_save_button)
dark_mode_button = QPushButton("Enable Dark Mode")
settings_dialog.layout().addWidget(dark_mode_button)
if is_dark_mode_active():
dark_mode_button.setText("Disable Dark Mode")
def deactivate_dark_mode_():
"""
Deactivate dark mode and update the main window.
This function deactivates dark mode and updates the main window with a notification.
Returns:
- None
"""
deactivate_dark_mode()
the_main_window.update_from_thread("Disabled Dark Mode")
the_main_window.light_mode()
settings_dialog.close()
dark_mode_button.clicked.connect(deactivate_dark_mode_)
else:
def activate_dark_mode_():
"""
Activate dark mode and update the main window.
This function activates dark mode and updates the main window with a notification.
Returns:
- None
"""
activate_dark_mode()
the_main_window.update_from_thread("Enabled Dark Mode")
the_main_window.dark_mode()
settings_dialog.close()
dark_mode_button.clicked.connect(activate_dark_mode_)
predefined_agents_button = QPushButton("Enable Predefined Agents (Good Results, Long Response Time)")
settings_dialog.layout().addWidget(predefined_agents_button)
try:
import crewai
if is_predefined_agents_setting_active():
predefined_agents_button.setText("Disable Predefined Agents (Bad Results, Short Response Time)")
def deactivate_predefined_agents_():
deactivate_predefined_agents_setting()
the_main_window.update_from_thread("Disabled Predefined Agents (Bad Results, Short Response Time)")
settings_dialog.close()
predefined_agents_button.clicked.connect(deactivate_predefined_agents_)
else:
def activate_predefined_agents_():
activate_predefined_agents_setting()
the_main_window.update_from_thread("Enabled Predefined Agents (Good Results, Long Response Time)")
settings_dialog.close()
predefined_agents_button.clicked.connect(activate_predefined_agents_)
except:
predefined_agents_button.setText("Install gpt-computer-assistant[agentic]")
online_tools_button = QPushButton("Enable Upsonic Tiger Tools - More Capability (Recommended)")
settings_dialog.layout().addWidget(online_tools_button)
if is_online_tools_setting_active():
online_tools_button.setText("Disable Upsonic Tiger Tools - Low Capability (Not Recommended)")
def deactivate_online_tools_():
deactivate_online_tools_setting()
the_main_window.update_from_thread("Disabled Upsonic Tiger Tools - Low Capability (Not Recommended)")
settings_dialog.close()
online_tools_button.clicked.connect(deactivate_online_tools_)
else:
def activate_online_tools_():
activate_online_tools_setting()
the_main_window.update_from_thread("Enabled Upsonic Tiger Tools - More Capability (Recommended)")
settings_dialog.close()
online_tools_button.clicked.connect(activate_online_tools_)
auto_stop_recording_button = QPushButton("Enable Auto Stop Recording")
settings_dialog.layout().addWidget(auto_stop_recording_button)
if is_auto_stop_recording_setting_active():
auto_stop_recording_button.setText("Disable Auto Stop Recording")
def deactivate_auto_stop_recording_():
deactivate_auto_stop_recording_setting()
the_main_window.update_from_thread("Disabled Auto Stop Recording")
settings_dialog.close()
auto_stop_recording_button.clicked.connect(deactivate_auto_stop_recording_)
else:
def activate_auto_stop_recording_():
activate_auto_stop_recording_setting()
the_main_window.update_from_thread("Enabled Auto Stop Recording")
settings_dialog.close()
auto_stop_recording_button.clicked.connect(activate_auto_stop_recording_)
api_key_label = QLabel("Wakeword - Pvporcupine API Key")
settings_dialog.layout().addWidget(api_key_label)
api_key_input = QLineEdit()
api_key = load_pvporcupine_api_key()
api_key_input.setText(api_key)
settings_dialog.layout().addWidget(api_key_input)
save_button = QPushButton("Save")
def save_api_key_(api_key):
first_time = True
if api_key != "CHANGE_ME":
first_time = False
save_pvporcupine_api_key(api_key)
the_main_window.update_from_thread("Wake word activated, just say 'Her Computer' or jarvis to activate the assistant")
if first_time:
the_main_window.wake_word_trigger()
settings_dialog.close()
save_button.clicked.connect(lambda: save_api_key_(api_key_input.text()))
settings_dialog.layout().addWidget(save_button)
wake_word_button = QPushButton("Enable Wake Word")
settings_dialog.layout().addWidget(wake_word_button)
missing_parts = False
try:
import pyaudio
except:
missing_parts = True
if api_key == "CHANGE_ME":
wake_word_button.setText("Please Set Pvporcupine API Key First")
elif missing_parts:
wake_word_button.setText("Please Install gpt-computer-assistant[wakeword]")
else:
if is_wake_word_active():
wake_word_button.setText("Disable Wake Word")
def deactivate_wake_word_():
deactivate_wake_word()
the_main_window.update_from_thread("Disabled Wake Word")
the_main_window.wake_word_active = False
settings_dialog.close()
wake_word_button.clicked.connect(deactivate_wake_word_)
else:
def activate_wake_word_():
activate_wake_word()
the_main_window.update_from_thread("Enabled Wake Word")
the_main_window.wake_word_active = True
the_main_window.wake_word_trigger()
settings_dialog.close()
wake_word_button.clicked.connect(activate_wake_word_)
wake_word_screen_button = QPushButton("Enable Screen Input for Wake Word Mode")
settings_dialog.layout().addWidget(wake_word_screen_button)
if is_wake_word_screen_setting_active():
wake_word_screen_button.setText("Disable Screen Input for Wake Word Mode")
def deactivate_auto_stop_recording_():
deactivate_wake_word_screen_setting()
the_main_window.update_from_thread("Disabled Screen Input for Wake Word Mode")
settings_dialog.close()
wake_word_screen_button.clicked.connect(deactivate_auto_stop_recording_)
else:
def activate_auto_stop_recording_():
activate_wake_word_screen_setting()
the_main_window.update_from_thread("Enabled Screen Input for Wake Word Mode")
settings_dialog.close()
wake_word_screen_button.clicked.connect(activate_auto_stop_recording_)
continuously_conversations_button = QPushButton("Enable Continuously Conversations")
settings_dialog.layout().addWidget(continuously_conversations_button)
if is_continuously_conversations_setting_active():
continuously_conversations_button.setText("Disable Continuously Conversations")
def deactivate_auto_stop_recording_():
deactivate_continuously_conversations_setting()
the_main_window.update_from_thread("Disabled Continuously Conversations")
settings_dialog.close()
continuously_conversations_button.clicked.connect(deactivate_auto_stop_recording_)
else:
def activate_auto_stop_recording_():
activate_continuously_conversations_setting()
the_main_window.update_from_thread("Enabled Continuously Conversations")
settings_dialog.close()
continuously_conversations_button.clicked.connect(activate_auto_stop_recording_)
settings_dialog.exec_()
|