From fec22adc58423166870af15a9a985094630b4f8a Mon Sep 17 00:00:00 2001 From: BuildTools Date: Sun, 25 Aug 2024 15:11:36 -0700 Subject: [PATCH] feat(config): add configuration options - add more configuration options for AUTOGGUF_MODEL_DIR_NAME, AUTOGGUF_OUTPUT_DIR_NAME, and AUTOGGUF_RESIZE_FACTOR (these get created on startup) - move some UI helper funtions out of AutoGGUF.py and into ui_update and Ta - optimize imports for utility classes - fix some missing imports --- src/AutoGGUF.py | 51 ++++++++++++-------------------------- src/DownloadThread.py | 2 +- src/ModelInfoDialog.py | 2 +- src/QuantizationThread.py | 5 ++-- src/TaskListItem.py | 32 ++++++++++++++++++++++++ src/imports_and_globals.py | 35 -------------------------- src/presets.py | 13 +++++++++- src/ui_update.py | 7 ++++++ src/utils.py | 9 +++---- 9 files changed, 76 insertions(+), 80 deletions(-) diff --git a/src/AutoGGUF.py b/src/AutoGGUF.py index b387cf8..b40352b 100644 --- a/src/AutoGGUF.py +++ b/src/AutoGGUF.py @@ -49,12 +49,20 @@ def __init__(self, args: List[str]) -> None: load_dotenv() # Loads the .env file - self.resize_factor = 1.1 # 10% increase/decrease + # Configuration + self.model_dir_name = os.environ.get("AUTOGGUF_MODEL_DIR_NAME", "models") + self.output_dir_name = os.environ.get( + "AUTOGGUF_OUTPUT_DIR_NAME", "quantized_models" + ) + + self.resize_factor = float( + os.environ.get("AUTOGGUF_RESIZE_FACTOR", 1.1) + ) # 10% increase/decrease self.default_width, self.default_height = self.parse_resolution() self.resize(self.default_width, self.default_height) - ensure_directory(os.path.abspath("quantized_models")) - ensure_directory(os.path.abspath("models")) + ensure_directory(os.path.abspath(self.output_dir_name)) + ensure_directory(os.path.abspath(self.model_dir_name)) # References self.update_base_model_visibility = partial( @@ -85,6 +93,9 @@ def __init__(self, args: List[str]) -> None: self.browse_imatrix = utils.browse_imatrix.__get__(self) self.get_models_data = utils.get_models_data.__get__(self) self.get_tasks_data = utils.get_tasks_data.__get__(self) + self.cancel_task = partial(TaskListItem.cancel_task, self) + self.delete_task = partial(TaskListItem.delete_task, self) + self.toggle_gpu_offload_auto = partial(ui_update.toggle_gpu_offload_auto, self) self.update_threads_spinbox = partial(ui_update.update_threads_spinbox, self) self.update_threads_slider = partial(ui_update.update_threads_slider, self) self.update_gpu_offload_spinbox = partial( @@ -238,7 +249,7 @@ def __init__(self, args: List[str]) -> None: # Models path models_layout = QHBoxLayout() - self.models_input = QLineEdit(os.path.abspath("models")) + self.models_input = QLineEdit(os.path.abspath(self.model_dir_name)) models_button = QPushButton(BROWSE) models_button.clicked.connect(self.browse_models) models_layout.addWidget(QLabel(MODELS_PATH)) @@ -248,7 +259,7 @@ def __init__(self, args: List[str]) -> None: # Output path output_layout = QHBoxLayout() - self.output_input = QLineEdit(os.path.abspath("quantized_models")) + self.output_input = QLineEdit(os.path.abspath(self.output_dir_name)) output_button = QPushButton(BROWSE) output_button.clicked.connect(self.browse_output) output_layout.addWidget(QLabel(OUTPUT_PATH)) @@ -1196,11 +1207,6 @@ def show_task_properties(self, item) -> None: model_info_dialog.exec() break - def toggle_gpu_offload_auto(self, state) -> None: - is_auto = state == Qt.CheckState.Checked - self.gpu_offload_slider.setEnabled(not is_auto) - self.gpu_offload_spinbox.setEnabled(not is_auto) - def cancel_task_by_item(self, item) -> None: task_item = self.task_list.itemWidget(item) for thread in self.quant_threads: @@ -1210,31 +1216,6 @@ def cancel_task_by_item(self, item) -> None: self.quant_threads.remove(thread) break - def cancel_task(self, item) -> None: - self.logger.info(CANCELLING_TASK.format(item.text())) - self.cancel_task_by_item(item) - - def delete_task(self, item) -> None: - self.logger.info(DELETING_TASK.format(item.text())) - - # Cancel the task first - self.cancel_task_by_item(item) - - reply = QMessageBox.question( - self, - CONFIRM_DELETION_TITLE, - CONFIRM_DELETION, - QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No, - QMessageBox.StandardButton.No, - ) - if reply == QMessageBox.StandardButton.Yes: - task_item = self.task_list.itemWidget(item) - row = self.task_list.row(item) - self.task_list.takeItem(row) - - if task_item: - task_item.deleteLater() - def create_label(self, text, tooltip) -> QLabel: label = QLabel(text) label.setToolTip(tooltip) diff --git a/src/DownloadThread.py b/src/DownloadThread.py index 210a4ac..2157c94 100644 --- a/src/DownloadThread.py +++ b/src/DownloadThread.py @@ -2,7 +2,7 @@ import zipfile import requests -from PySide6.QtCore import * +from PySide6.QtCore import QThread, Signal class DownloadThread(QThread): diff --git a/src/ModelInfoDialog.py b/src/ModelInfoDialog.py index 849abe4..d2b0245 100644 --- a/src/ModelInfoDialog.py +++ b/src/ModelInfoDialog.py @@ -1,4 +1,4 @@ -from PySide6.QtWidgets import * +from PySide6.QtWidgets import QVBoxLayout, QTextEdit, QDialog, QPushButton class ModelInfoDialog(QDialog): diff --git a/src/QuantizationThread.py b/src/QuantizationThread.py index fb90665..bbc4540 100644 --- a/src/QuantizationThread.py +++ b/src/QuantizationThread.py @@ -1,10 +1,11 @@ +import os import signal import subprocess -from PySide6.QtCore import * +from PySide6.QtCore import Signal, QThread from imports_and_globals import open_file_safe -from Localizations import * +from Localizations import IN_PROGRESS, COMPLETED class QuantizationThread(QThread): diff --git a/src/TaskListItem.py b/src/TaskListItem.py index 8d9e50f..3888fec 100644 --- a/src/TaskListItem.py +++ b/src/TaskListItem.py @@ -1,6 +1,13 @@ from PySide6.QtCore import * from PySide6.QtWidgets import * +from Localizations import ( + DELETING_TASK, + CANCELLING_TASK, + CONFIRM_DELETION_TITLE, + CONFIRM_DELETION, +) + class TaskListItem(QWidget): def __init__( @@ -30,6 +37,31 @@ def __init__( self.progress_timer.timeout.connect(self.update_progress) self.progress_value = 0 + def cancel_task(self, item) -> None: + self.logger.info(CANCELLING_TASK.format(item.text())) + self.cancel_task_by_item(item) + + def delete_task(self, item) -> None: + self.logger.info(DELETING_TASK.format(item.text())) + + # Cancel the task first + self.cancel_task_by_item(item) + + reply = QMessageBox.question( + self, + CONFIRM_DELETION_TITLE, + CONFIRM_DELETION, + QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No, + QMessageBox.StandardButton.No, + ) + if reply == QMessageBox.StandardButton.Yes: + task_item = self.task_list.itemWidget(item) + row = self.task_list.row(item) + self.task_list.takeItem(row) + + if task_item: + task_item.deleteLater() + def update_status(self, status) -> None: self.status = status self.status_label.setText(status) diff --git a/src/imports_and_globals.py b/src/imports_and_globals.py index 176f63f..f99e8e0 100644 --- a/src/imports_and_globals.py +++ b/src/imports_and_globals.py @@ -1,44 +1,9 @@ -import os import sys from typing import TextIO, Union -import psutil -import subprocess -import time -import signal -import json -import platform -import requests -import zipfile -from datetime import datetime from PySide6.QtWidgets import ( - QApplication, - QMainWindow, - QVBoxLayout, - QHBoxLayout, - QWidget, - QPushButton, - QListWidget, - QLineEdit, - QLabel, - QFileDialog, - QProgressBar, - QComboBox, - QTextEdit, - QCheckBox, - QGroupBox, - QFormLayout, - QScrollArea, - QSlider, - QSpinBox, - QListWidgetItem, QMessageBox, - QDialog, - QPlainTextEdit, - QMenu, ) -from PySide6.QtCore import QTimer, Signal, QThread, Qt, QSize -from PySide6.QtGui import QCloseEvent, QAction from Localizations import * diff --git a/src/presets.py b/src/presets.py index c203349..5408d21 100644 --- a/src/presets.py +++ b/src/presets.py @@ -1,7 +1,18 @@ import json +from PySide6.QtCore import Qt from PySide6.QtWidgets import QFileDialog, QMessageBox -from Localizations import * +from Localizations import ( + SAVING_PRESET, + SAVE_PRESET, + JSON_FILES, + PRESET_SAVED, + PRESET_SAVED_TO, + LOADING_PRESET, + LOAD_PRESET, + PRESET_LOADED, + PRESET_LOADED_FROM, +) def save_preset(self) -> None: diff --git a/src/ui_update.py b/src/ui_update.py index bf165c7..f1085b8 100644 --- a/src/ui_update.py +++ b/src/ui_update.py @@ -1,10 +1,17 @@ from PySide6.QtCore import QTimer +from PySide6.QtGui import Qt from Localizations import * import psutil from error_handling import show_error +def toggle_gpu_offload_auto(self, state) -> None: + is_auto = state == Qt.CheckState.Checked + self.gpu_offload_slider.setEnabled(not is_auto) + self.gpu_offload_spinbox.setEnabled(not is_auto) + + def update_model_info(logger, self, model_info) -> None: logger.debug(UPDATING_MODEL_INFO.format(model_info)) pass diff --git a/src/utils.py b/src/utils.py index b4cf27a..e977ecb 100644 --- a/src/utils.py +++ b/src/utils.py @@ -1,13 +1,12 @@ -from typing import Any, Dict, List, Union +from typing import Any, Union +import requests from PySide6.QtCore import Qt from PySide6.QtWidgets import QFileDialog -from error_handling import show_error -from Localizations import * -import requests - from DownloadThread import DownloadThread +from Localizations import * +from error_handling import show_error from imports_and_globals import ensure_directory