|
5 | 5 | import urllib.request
|
6 | 6 | from datetime import datetime
|
7 | 7 | from functools import partial, wraps
|
8 |
| -from typing import List |
| 8 | +from typing import Any, List, Union |
9 | 9 |
|
10 | 10 | from PySide6.QtCore import *
|
11 | 11 | from PySide6.QtGui import *
|
@@ -71,7 +71,7 @@ def __init__(self, args: List[str]) -> None:
|
71 | 71 |
|
72 | 72 | self.parse_resolution = ui_update.parse_resolution.__get__(self)
|
73 | 73 |
|
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")) |
75 | 75 |
|
76 | 76 | width, height = self.parse_resolution()
|
77 | 77 | self.logger = Logger("AutoGGUF", self.log_dir_name)
|
@@ -775,7 +775,7 @@ def __init__(self, args: List[str]) -> None:
|
775 | 775 | # Quantize button layout
|
776 | 776 | quantize_layout = QHBoxLayout()
|
777 | 777 | quantize_button = QPushButton(QUANTIZE_MODEL)
|
778 |
| - quantize_button.clicked.connect(self.quantize_model) |
| 778 | + quantize_button.clicked[bool].connect(self.quantize_model_handler) |
779 | 779 | save_preset_button = QPushButton(SAVE_PRESET)
|
780 | 780 | save_preset_button.clicked.connect(self.save_preset)
|
781 | 781 | load_preset_button = QPushButton(LOAD_PRESET)
|
@@ -1101,6 +1101,20 @@ def __init__(self, args: List[str]) -> None:
|
1101 | 1101 | self.logger.info(AUTOGGUF_INITIALIZATION_COMPLETE)
|
1102 | 1102 | self.logger.info(STARTUP_ELASPED_TIME.format(init_timer.elapsed()))
|
1103 | 1103 |
|
| 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 | + |
1104 | 1118 | def resizeEvent(self, event) -> None:
|
1105 | 1119 | super().resizeEvent(event)
|
1106 | 1120 | path = QPainterPath()
|
@@ -1254,23 +1268,6 @@ def download_finished(self, extract_dir) -> None:
|
1254 | 1268 | if index >= 0:
|
1255 | 1269 | self.backend_combo.setCurrentIndex(index)
|
1256 | 1270 |
|
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 |
| - |
1274 | 1271 | def load_models(self) -> None:
|
1275 | 1272 | self.logger.info(LOADING_MODELS)
|
1276 | 1273 | models_dir = self.models_input.text()
|
@@ -1698,10 +1695,9 @@ def merge_gguf(self, model_dir: str, output_dir: str) -> None:
|
1698 | 1695 | show_error(self.logger, "Error starting merge GGUF task: {}".format(e))
|
1699 | 1696 | self.logger.info("Split GGUF task finished.")
|
1700 | 1697 |
|
1701 |
| - def quantize_model(self) -> None: |
| 1698 | + def quantize_model(self, return_command=False) -> str: |
1702 | 1699 | self.logger.info(STARTING_MODEL_QUANTIZATION)
|
1703 | 1700 | try:
|
1704 |
| - self.validate_quantization_inputs() |
1705 | 1701 | selected_item = self.model_tree.currentItem()
|
1706 | 1702 | if not selected_item:
|
1707 | 1703 | raise ValueError(NO_MODEL_SELECTED)
|
@@ -1822,6 +1818,12 @@ def quantize_model(self) -> None:
|
1822 | 1818 | if self.extra_arguments.text():
|
1823 | 1819 | command.extend(self.extra_arguments.text().split())
|
1824 | 1820 |
|
| 1821 | + if return_command: |
| 1822 | + self.logger.info( |
| 1823 | + f"{QUANTIZATION_COMMAND}: {str(' '.join(command))}" |
| 1824 | + ) |
| 1825 | + return str(" ".join(command)) |
| 1826 | + |
1825 | 1827 | logs_path = self.logs_input.text()
|
1826 | 1828 | ensure_directory(logs_path)
|
1827 | 1829 |
|
|
0 commit comments