Skip to content

Commit 749f321

Browse files
committed
feat(ui): support shift clicking to get quantization command
- support shift clicking Quantize Model button to get quantize command - clean up imports in AutoGGUF.py and add localization keys - use str() for getting log_dir_name - remove legacy validate_quantization_inputs() function - add return_command parameter to quantize_model() function
1 parent 6aaefb2 commit 749f321

File tree

2 files changed

+27
-22
lines changed

2 files changed

+27
-22
lines changed

src/AutoGGUF.py

+24-22
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import urllib.request
66
from datetime import datetime
77
from functools import partial, wraps
8-
from typing import List
8+
from typing import Any, List, Union
99

1010
from PySide6.QtCore import *
1111
from PySide6.QtGui import *
@@ -71,7 +71,7 @@ def __init__(self, args: List[str]) -> None:
7171

7272
self.parse_resolution = ui_update.parse_resolution.__get__(self)
7373

74-
self.log_dir_name = os.environ.get("AUTOGGUF_LOG_DIR_NAME", "logs")
74+
self.log_dir_name = str(os.environ.get("AUTOGGUF_LOG_DIR_NAME", "logs"))
7575

7676
width, height = self.parse_resolution()
7777
self.logger = Logger("AutoGGUF", self.log_dir_name)
@@ -775,7 +775,7 @@ def __init__(self, args: List[str]) -> None:
775775
# Quantize button layout
776776
quantize_layout = QHBoxLayout()
777777
quantize_button = QPushButton(QUANTIZE_MODEL)
778-
quantize_button.clicked.connect(self.quantize_model)
778+
quantize_button.clicked[bool].connect(self.quantize_model_handler)
779779
save_preset_button = QPushButton(SAVE_PRESET)
780780
save_preset_button.clicked.connect(self.save_preset)
781781
load_preset_button = QPushButton(LOAD_PRESET)
@@ -1101,6 +1101,20 @@ def __init__(self, args: List[str]) -> None:
11011101
self.logger.info(AUTOGGUF_INITIALIZATION_COMPLETE)
11021102
self.logger.info(STARTUP_ELASPED_TIME.format(init_timer.elapsed()))
11031103

1104+
def quantize_model_handler(self) -> None:
1105+
if QApplication.keyboardModifiers() == Qt.ShiftModifier and self.quantize_model(
1106+
return_command=True
1107+
):
1108+
QApplication.clipboard().setText(self.quantize_model(return_command=True))
1109+
QMessageBox.information(
1110+
None,
1111+
INFO,
1112+
f"{COPIED_COMMAND_TO_CLIPBOARD} "
1113+
+ f"<code style='font-family: monospace; white-space: pre;'>{self.quantize_model(return_command=True)}</code>",
1114+
)
1115+
else:
1116+
self.quantize_model()
1117+
11041118
def resizeEvent(self, event) -> None:
11051119
super().resizeEvent(event)
11061120
path = QPainterPath()
@@ -1254,23 +1268,6 @@ def download_finished(self, extract_dir) -> None:
12541268
if index >= 0:
12551269
self.backend_combo.setCurrentIndex(index)
12561270

1257-
def validate_quantization_inputs(self) -> None:
1258-
self.logger.debug(VALIDATING_QUANTIZATION_INPUTS)
1259-
errors = []
1260-
if not self.backend_combo.currentData():
1261-
errors.append(NO_BACKEND_SELECTED)
1262-
if not self.models_input.text():
1263-
errors.append(MODELS_PATH_REQUIRED)
1264-
if not self.output_input.text():
1265-
errors.append(OUTPUT_PATH_REQUIRED)
1266-
if not self.logs_input.text():
1267-
errors.append(LOGS_PATH_REQUIRED)
1268-
if not self.model_tree.currentItem():
1269-
errors.append(NO_MODEL_SELECTED)
1270-
1271-
if errors:
1272-
raise ValueError("\n".join(errors))
1273-
12741271
def load_models(self) -> None:
12751272
self.logger.info(LOADING_MODELS)
12761273
models_dir = self.models_input.text()
@@ -1698,10 +1695,9 @@ def merge_gguf(self, model_dir: str, output_dir: str) -> None:
16981695
show_error(self.logger, "Error starting merge GGUF task: {}".format(e))
16991696
self.logger.info("Split GGUF task finished.")
17001697

1701-
def quantize_model(self) -> None:
1698+
def quantize_model(self, return_command=False) -> str:
17021699
self.logger.info(STARTING_MODEL_QUANTIZATION)
17031700
try:
1704-
self.validate_quantization_inputs()
17051701
selected_item = self.model_tree.currentItem()
17061702
if not selected_item:
17071703
raise ValueError(NO_MODEL_SELECTED)
@@ -1822,6 +1818,12 @@ def quantize_model(self) -> None:
18221818
if self.extra_arguments.text():
18231819
command.extend(self.extra_arguments.text().split())
18241820

1821+
if return_command:
1822+
self.logger.info(
1823+
f"{QUANTIZATION_COMMAND}: {str(' '.join(command))}"
1824+
)
1825+
return str(" ".join(command))
1826+
18251827
logs_path = self.logs_input.text()
18261828
ensure_directory(logs_path)
18271829

src/Localizations.py

+3
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,9 @@ def __init__(self):
454454

455455
self.EXTRA_COMMAND_ARGUMENTS = "Additional command-line arguments"
456456

457+
self.INFO = "Info"
458+
self.COPIED_COMMAND_TO_CLIPBOARD = "Copied command to clipboard:"
459+
457460

458461
class _French(_Localization):
459462
def __init__(self):

0 commit comments

Comments
 (0)