refactor: move some strings to localizations

This commit is contained in:
BuildTools 2024-08-05 17:41:12 -07:00
parent ab7ffb0ad3
commit eca2ecc785
No known key found for this signature in database
GPG Key ID: 3270C066C15D530B
3 changed files with 54 additions and 61 deletions

View File

@ -20,6 +20,19 @@
from imports_and_globals import ensure_directory, open_file_safe, resource_path
from localizations import *
from functools import wraps
def handle_load_preset_error(func):
@wraps(func)
def wrapper(self, *args, **kwargs):
try:
return func(self, *args, **kwargs)
except Exception as e:
QMessageBox.critical(self, ERROR, FAILED_TO_LOAD_PRESET.format(str(e)))
return wrapper
class AutoGGUF(QMainWindow):
def __init__(self):
@ -679,11 +692,11 @@ def save_preset(self):
)
self.logger.info(PRESET_SAVED_TO.format(file_name))
@handle_load_preset_error
def load_preset(self):
self.logger.info(LOADING_PRESET)
file_name, _ = QFileDialog.getOpenFileName(self, LOAD_PRESET, "", JSON_FILES)
if file_name:
try:
with open(file_name, "r") as f:
preset = json.load(f)
@ -703,9 +716,7 @@ def load_preset(self):
self.use_output_tensor_type.setChecked(
preset.get("use_output_tensor_type", False)
)
self.output_tensor_type.setCurrentText(
preset.get("output_tensor_type", "")
)
self.output_tensor_type.setCurrentText(preset.get("output_tensor_type", ""))
self.use_token_embedding_type.setChecked(
preset.get("use_token_embedding_type", False)
)
@ -724,8 +735,6 @@ def load_preset(self):
QMessageBox.information(
self, PRESET_LOADED, PRESET_LOADED_FROM.format(file_name)
)
except Exception as e:
QMessageBox.critical(self, ERROR, FAILED_TO_LOAD_PRESET.format(str(e)))
self.logger.info(PRESET_LOADED_FROM.format(file_name))
def save_task_preset(self, task_item):
@ -812,9 +821,7 @@ def delete_lora_adapter_item(self, adapter_widget):
def browse_hf_model_input(self):
self.logger.info("Browsing for HuggingFace model directory")
model_dir = QFileDialog.getExistingDirectory(
self, "Select HuggingFace Model Directory"
)
model_dir = QFileDialog.getExistingDirectory(self, SELECT_HF_MODEL_DIRECTORY)
if model_dir:
self.hf_model_input.setText(os.path.abspath(model_dir))
@ -1340,11 +1347,6 @@ def cancel_task(self, item):
task_item.update_status(CANCELED)
break
def retry_task(self, item):
task_item = self.task_list.itemWidget(item)
# TODO: Implement the logic to restart the task
pass
def delete_task(self, item):
self.logger.info(DELETING_TASK.format(item.text()))
reply = QMessageBox.question(
@ -1666,7 +1668,6 @@ def quantize_model(self):
def update_model_info(self, model_info):
self.logger.debug(UPDATING_MODEL_INFO.format(model_info))
# TODO: Do something with this
pass
def parse_progress(self, line, task_item):
@ -1734,17 +1735,6 @@ def browse_imatrix_output(self):
if output_file:
self.imatrix_output.setText(os.path.abspath(output_file))
def update_gpu_offload_spinbox(self, value):
self.gpu_offload_spinbox.setValue(value)
def update_gpu_offload_slider(self, value):
self.gpu_offload_slider.setValue(value)
def toggle_gpu_offload_auto(self, state):
is_auto = state == Qt.CheckState.Checked
self.gpu_offload_slider.setEnabled(not is_auto)
self.gpu_offload_spinbox.setEnabled(not is_auto)
def generate_imatrix(self):
self.logger.info(STARTING_IMATRIX_GENERATION)
try:

View File

@ -1,6 +1,7 @@
from PyQt6.QtWidgets import QMessageBox
from localizations import *
def show_error(logger, message):
logger.error(ERROR_MESSAGE.format(message))
QMessageBox.critical(None, ERROR, message)

View File

@ -100,6 +100,7 @@ def __init__(self):
self.SPLIT_MAX_SIZE = ""
self.DRY_RUN = ""
self.CONVERT_HF_TO_GGUF = ""
self.SELECT_HF_MODEL_DIRECTORY = ""
# General Messages
self.ERROR = ""
@ -372,6 +373,7 @@ def __init__(self):
self.SPLIT_MAX_SIZE = "Split Max Size:"
self.DRY_RUN = "Dry Run"
self.CONVERT_HF_TO_GGUF = "Convert HF to GGUF"
self.SELECT_HF_MODEL_DIRECTORY = "Select HuggingFace Model Directory"
# General Messages
self.ERROR = "Error"